Hallo, <br>arbeite mit den Francois Piette-Komponenten TWSocketServer/TWSocketClient und <br>möchte die MAC-Adresse eines Clients aus der IP-Adresse ermitteln. Ein ARP-Request also.<br>Wie geht das ?<br>Gruss, Uwe.
Announcement
Collapse
No announcement yet.
ARP Request, aus IP die MAC-Adr. eines Clients ermitteln
Collapse
X
-
Hi!
Da helfen die Piette-Komponenten nicht weiter (dessen Programmierstil eh unter aller Sau ist).
nimm folgendes:
<pre>
unit arp;
// (C) 2000 T.Kaluza
interface
uses sysutils,windows, winsock;
type TIPAddr = u_long;
TMACAddr = array[0..5] of char;
{$EXTERNALSYM SendArp}
function SendARP (DestIP,SrcIP: TIPAddr; var TMacAddr: TMACAddr; var len: u_long): DWORD stdcall;
function MACtoString(mac: TMACAddr): string;
procedure getMacbyHost(host: string; var mac: TMACAddr);
implementation
const
iphlpapi = 'iphlpapi.dll';
{ Sending an ARP Request }
function sendARP; external iphlpapi name 'SendARP';
function MACtoString(mac: TMACAddr): string;
begin
result:=IntToHex(ord(mac[0]),2)
+IntToHex(ord(mac[1]),2)
+'.'+IntToHex(ord(mac[2]),2)
+IntToHex(ord(mac[3]),2)+'.'
+IntToHex(ord(mac[4]),2)
+IntToHex(ord(mac[5]),2);
end;
procedure getMacbyHost(host: string;var mac: TMACAddr);
var l: integer;
begin
mac[0]:=#0;
mac[1]:=#0;
mac[2]:=#0;
mac[3]:=#0;
mac[4]:=#0;
mac[5]:=#0;
l:=sizeof(TMACAddr);
sendARP(inet_addr(PChar(host)),inet_addr(PChar('lo calhost')),mac,l);
end;
end.
</pre>
Der Host muss schon eine IP-Adresse sein, die Routine löst nicht zusätzlich Hostnamen in IP-Adressen auf.
Grüße
Tim
-
Dort gibt es noch mehr Infos über diese sehr nützliche Library:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tcpip/tcpip_2g6r.asp
Verfügbar ist die iphlpapi folgendermassen:
<b>Run-Time Requirements</b>
The IP Helper API is supported on Microsoft® Windows® 98, Microsoft Windows® Millennium Edition, on Microsoft® Windows NT® version 4.0 with Service Pack 4, Microsoft Windows® 2000, Microsoft Windows® XP and Microsoft Windows® .NET Server. Not all of the operating systems support all of the functions. If an IP Helper function on a platform is called that does not support that function, a return value of ERROR_NOT_SUPPORTED is received. For more specific information about which operating systems support a particular function, refer to the Requirements sections in the documentation.
cu
Tim
Comment
-
Hiho...
super geiles Ding... nicht schlecht... wollte mich dafür bei dir bedanken, da ich damit in meiner momentanen Entwicklung viel anfangen kann...
Dein Programmierstil könnte duch ein kleines Formatierungsprogramm auf Fordermann gebracht werden ;-)
Aber sonst absolut 100%...
Alles Gute weiterhin...
Manfred
http://www.whoopsie.d
Comment
Comment