Re:ARP and mac address (INDY ?)
Quote
> Does anyone have an example of using ARP to determine the MAC address
> associated with a specific IP address.
Use IP Helper API to do that. You can find a port for this API at Jedi
website http://www.delphi-jedi.org
Here is a sample code I wrote. It displays MAC address among other useful
informations:
procedure TIfConfForm.DisplayIfConf;
var
AdapterInfo : IP_ADAPTER_INFO;
pAdapterInfo : PIP_ADAPTER_INFO;
BufSize : DWORD;
Status : DWORD;
I : Integer;
Buf : String;
const
BooleanToStr : array [Boolean] of String = ('FALSE', 'TRUE');
begin
DisplayMemo.Clear;
BufSize := SizeOf(AdapterInfo);
pAdapterInfo := @AdapterInfo;
Status := GetAdaptersInfo(pAdapterInfo, BufSize);
if Status <> ERROR_SUCCESS then begin
case Status of
ERROR_NOT_SUPPORTED :
Display('GetAdaptersInfo is not supported by the operating ' +
'system running on the local computer.');
ERROR_NO_DATA :
Display('No network adapter on the local computer.');
else
Display('GetAdaptersInfo failed with error #' +
IntToStr(Status));
end;
Exit;
end;
repeat
Display('Description: ' + pAdapterInfo^.Description);
Display('Name: ' + pAdapterInfo^.AdapterName);
Buf := '';
for I := 0 to pAdapterInfo^.AddressLength - 1 do
Buf := Buf + '-' + IntToHex(pAdapterInfo^.Address[I], 2);
Delete(Buf, 1, 1);
Display('MAC address: ' + Buf);
Display('IP address: ' +
IpListToStr(@pAdapterInfo^.IpAddressList));
Display('Gateway: ' +
IpListToStr(@pAdapterInfo^.GatewayList));
DIsplay('DHCP enabled: ' + BooleanToStr[pAdapterInfo^.DhcpEnabled
<> 0]);
Display('DHCP: ' + IpListToStr(@pAdapterInfo^.DhcpServer));
DIsplay('Have WINS: ' + BooleanToStr[pAdapterInfo^.HaveWins]);
Display('Primary WINS: ' +
IpListToStr(@pAdapterInfo^.PrimaryWinsServer));
Display('Secondary WINS: ' +
IpListToStr(@pAdapterInfo^.SecondaryWinsServer));
pAdapterInfo := pAdapterInfo^.Next;
until pAdapterInfo = nil;
Display('Done.');
end;
--
francois.pie...@overbyte.be
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be