DELPHI的最好
解决方案 »
- TADOquery Locate 方法的最后一个参数如何用??
- ehlib dbgrideh + ClientDataSet 过滤中文问题
- 修改内存地址寄存器的值
- 我的三层系统,用到cxGrid,cxGrid新加的记录怎么通过ClientDataSet写到数据库中去?
- 没有找到dpl,找不到指定的模块
- Delphi如何存取Oracle数据库中的图片数据呢?
- midas 连接问题
- 紧急求助!!!!!!!!!!!!!!!!!!!!!~~~~~~~~
- 那里可以下载delphi6的update pack 1,要求下载地址以http开头,我单位把ftp端口给封了,没有办法下载。
- 关于查询的一个小问题
- 奇怪,fastreport2.5 不能显示‘加工’两个字?
- 注册表中Shell把explorer.exe改为我的程序后如何在程序中使用代码恢复桌面?
使用 GetIpNetTable函数.
请大家回贴捡分。
//代码在下面unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, WinSock;const
MAXLEN_PHYSADDR = 8;
type
TMACArr6 = array [0..MAXLEN_PHYSADDR-1] of Byte;
TMAC_ADDR6 = record
case integer of
0: (bAddr: TMACArr6);
1: (DW: DWORD; WD: WORD);
end;
PMAC_ADDR6 = ^TMAC_ADDR6;
TMIB_IPNETROW = Record
dwIndex: DWORD;
dwPhysAddrLen: DWORD;
bPhysAddr: TMACArr6;
dwAddr: DWORD;
dwType: DWORD;
end;
PMIB_IPNETROW = ^TMIB_IPNETROW;
TMIB_IPNETTABLE = Record
dwNumEntries: DWORD;
table: array [0..10000] of TMIB_IPNETROW;
end;
PMIB_IPNETTABLE = ^TMIB_IPNETTABLE; TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure GetARPTable();
public
{ Public declarations }
end;var
Form1: TForm1;function GetIpNetTable(pIpNetTable: PMIB_IPNETTABLE; var pdwSize: DWORD;
bOrder: Boolean): DWORD; stdcall;
external 'IPHLPAPI.DLL' name 'GetIpNetTable';
function SetIpNetEntry(pArpEntry: PMIB_IPNETROW): DWORD; stdcall;
external 'IPHLPAPI.DLL' name 'SetIpNetEntry';implementation{$R *.DFM}
//取得ARP表所有的行
procedure TForm1.GetARPTable();
var
buf: array [0..4095] of BYTE;
pIPNet: PMIB_IPNETTABLE;
dwSize: DWORD;
i: integer;
pmac: PMAC_ADDR6;
smac: string;
begin
pIPNet := @buf;
dwSize := 4096;
if GetIpNetTable(pIPNet, dwSize, True) = 0 then
for i := 0 to pIPNet.dwNumEntries-1 do // 循环,ARP表每条处理一次
with pIPNet.table[i] do
begin
pmac := @bPhysAddr;
if (pmac.DW <> 0) and (pmac.WD <> 0) then // 忽略MAC全0的行
begin
// inet_ntoa(in_addr(dwAddr)); // 得到该行IP与MAC
smac := IntToHex(bPhysAddr[0],2)+
IntToHex(bPhysAddr[1],2)+
IntToHex(bPhysAddr[2],2)+
IntToHex(bPhysAddr[3],2)+
IntToHex(bPhysAddr[4],2)+
IntToHex(bPhysAddr[5],2);
Memo1.Lines.Add(inet_ntoa(in_addr(dwAddr)) + ' ' + smac);
end;
end;
end;
// 修改一个已存在的行
procedure ChangeIPNetRow(Adapter: DWORD; dwAddr: DWORD; bAddr: TMACArr6);
var
mibrow: TMIB_IPNETROW;
begin
mibrow.dwIndex := Adapter;
mibrow.dwPhysAddrLen := 6;
mibrow.bPhysAddr := bAddr;
mibrow.dwAddr := dwAddr;
mibrow.dwType := 2; // invalid
SetIpNetEntry(@mibrow);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
GetARPTable();
end;end.