Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get MAC number in local net? 1

Status
Not open for further replies.

xor2

Programmer
Mar 24, 2005
22
0
0
How to get mac number in localnet. For host for example: 192.168.0.57 In delphi ?
 
I have written this procedures in Delphi.
I will paste it here, cause i have not found it in internet, maybe somebody will use it.

Uses Winsock;

Function SendARP (DestIp: DWORD; srcIP: DWORD; pMacAddr: pointer; PhyAddrLen: Pointer): DWORD;stdcall; external 'iphlpapi.dll';

Function getRemoteMacAdress (var address: String): Boolean;
var
dwRemoteIP: DWORD;
PhyAddrLen: Longword;
pMacAddr : array [0..1] of Longword;
temp: array [0..5] of byte;
I: Byte;
begin
Result := false;
dwremoteIP := inet_addr (@address[1]);
if dwremoteIP <> 0 then begin
PhyAddrLen := 6;
if SendARP (dwremoteIP, 0, @pMacAddr, @PhyAddrLen) = NO_ERROR then begin
if (PhyAddrLen <> 0) and (pMacAddr[0] <> 0) then begin
Move (pMacAddr, temp, 6);
address := '';
For I := 0 to 5 do address := address + inttohex (temp, 2)+'-';
Delete (address, Length (address), 1);
Result := true;
end;
end;
end;
end;
 
Thank you for sharing your solution.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top