Delphi獲取MAC地址的代碼,用多種方法取得MAC地址,1、通過IP地址取得MAC地址,2、獲取多網卡的Mac地址,下面具體看代碼吧:
1、利用IP地址獲取Mac:
01
uses
02
WinSock;
03
Function
sendarp(ipaddr:ulong;
04
temp:dWord;
05
ulMacaddr:
pointer
;
06
ulMacaddrleng:
pointer
) : DWord; StdCall; External ‘Iphlpapi
.
dll’ Name ‘SendARP’;
07
procedure
TForm1
.
Button1Click(Sender: TObject);
08
var
09
myip:ulong;
10
myMac:
array
[
0..5
]
of
byte
;
11
myMaclength:ulong;
12
r:
integer
;
13
begin
14
myip:=inet_addr(
PChar
(’
192.168.6.180
′));
15
mymaclength:=length(myMac);
16
r:=sendarp(myip,
0
,@mymac,@myMaclength);
17
label1
.
caption:=’errorcode:’+inttostr(r);
18
label2
.
caption:=format(‘%
2.
2x:%
2.
2x:%
2.
2x:%
2.
2x:%
2.
2x:%
2.
2x’,[myMac[
0
],myMac[
1
],myMac[
2
],myMac[
3
],myMac[
4
],myMac[
5
]]);
19
end
;
2、獲取多網卡的Mac地址:
vIEw source