Delphi:获取路由器的MAC [英] Delphi: Get MAC of Router
问题描述
我的代码: / p>
var
idsnmp:tidsnmp;
val:string;
begin
idsnmp:= tidsnmp.create;
try
idsnmp.QuickSend('。1.3.6.1.2.1.4.22.1.2','public','10.0.0.1',val);
showmessage(val);
finally
idsnmp.free;
结束
结束
其中10.0.0.1是我的路由器。
唉,QuickSend总是发送由对等体#10054重新连接。我试图修改MIB-OID,我也尝试了IP 127.0.0.1哪个连接永远不会失败。我没有在Google上找到有关TIdSNMP的任何可用的教程。 : - (
Regards
Daniel Marschall
您可以使用 SendARP
功能来获取Mac地址。
查看此示例
使用
Windows,
WinSock,
SysUtils;
函数SendArp(DestIP,SrcIP:ULONG; pMacAddr:pointer; PhyAddrLen :指针):DWord; StdCall;外部'iphlpapi.dll'名称'SendARP';
函数GetMacAddr(const IPAddress:string; var ErrCode:DWORD):string;
var
MacAddr:Byte的数组[0..5];
DestIP:ULONG;
PhyAddrLen:ULONG;
WSAData:TWSAData;
begin
结果:='';
WSAStartup($ 0101,WSAData);
try
ZeroMemory(@ MacAddr,SizeOf(MacAddr));
DestIP:= inet_addr(PAnsiChar ));
PhyAddrLen:= SizeOf(MacAddr);
ErrCode:= SendArp(DestI P,0,@ MacAddr,@ PhyAddrLen);
如果ErrCode = S_OK然后
结果:=格式('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',[MacAddr [0] MacAddr [1],MacAddr [2],MacAddr [3],MacAddr [4],MacAddr [5]])
finally
WSACleanup;
结束
结束
I am using Delphi and I want to determinate the physical MAC address of a network device in my network, in this case the Router itself.
My code:
var
idsnmp: tidsnmp;
val:string;
begin
idsnmp := tidsnmp.create;
try
idsnmp.QuickSend('.1.3.6.1.2.1.4.22.1.2', 'public', '10.0.0.1', val);
showmessage(val);
finally
idsnmp.free;
end;
end;
where 10.0.0.1 is my router.
Alas, QuickSend does always send "Connection reset by peer #10054". I tried to modify the MIB-OID and I also tried the IP 127.0.0.1 which connection should never fail. I did not find any useable Tutorials about TIdSNMP at Google. :-(
Regards Daniel Marschall
You can use the SendARP
function to get the Mac Address.
check this sample
uses
Windows,
WinSock,
SysUtils;
function SendArp(DestIP,SrcIP:ULONG;pMacAddr:pointer;PhyAddrLen:pointer) : DWord; StdCall; external 'iphlpapi.dll' name 'SendARP';
function GetMacAddr(const IPAddress: string; var ErrCode : DWORD): string;
var
MacAddr : Array[0..5] of Byte;
DestIP : ULONG;
PhyAddrLen : ULONG;
WSAData : TWSAData;
begin
Result :='';
WSAStartup($0101, WSAData);
try
ZeroMemory(@MacAddr,SizeOf(MacAddr));
DestIP :=inet_addr(PAnsiChar(IPAddress));
PhyAddrLen:=SizeOf(MacAddr);
ErrCode :=SendArp(DestIP,0,@MacAddr,@PhyAddrLen);
if ErrCode = S_OK then
Result:=Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',[MacAddr[0], MacAddr[1],MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]])
finally
WSACleanup;
end;
end;
这篇关于Delphi:获取路由器的MAC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!