H
honestman
Unregistered / Unconfirmed
GUEST, unregistred user!
我用如下函数取MAC地址,需要输入参数a:integer,也就是LAN 适配器 (LANA) 号。
我在几台机器上试过用0,都可以取出正确的MAC地址,但是是否任何机器都可以用0呢?
是否一定要装了NetBIOS协议的机子才可以用这种方法取MAC地址呢?
uses Nb30
Function NBGetAdapterAddress(a:integer) : String;
Implementation
{$R *.DFM}
Procedure TForm1.Button1Click(Sender : TObject);
Begin
label1.Caption:=NBGetAdapterAddress(StrtoInt(Edit1.Text));
End;
Function NBGetAdapterAddress(a:Integer) : String;
Var
NCB : TNCB; // Netbios control block //NetBios控制块
ADAPTER : TADAPTERSTATUS; // Netbios adapter status//取网卡状态
LANAENUM : TLANAENUM; // Netbios lana
intIdx : Integer; // Temporary work value//临时变量
cRC : Char; // Netbios return code//NetBios返回值
strTemp : String; // Temporary string//临时变量
Begin
// Initialize
Result := '';
Try
// Zero control blocl
ZeroMemory(@NCB, SizeOf(NCB));
// Issue enum command
NCB.ncb_command := Chr(NCBENUM);
cRC := NetBios(@NCB);
// Reissue enum command
NCB.ncb_buffer := @LANAENUM;
NCB.ncb_length := SizeOf(LANAENUM);
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Reset adapter
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBRESET);
NCB.ncb_lana_num := LANAENUM.lana[a];
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Get adapter address
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBASTAT);
NCB.ncb_lana_num := LANAENUM.lana[a];
StrPCopy(NCB.ncb_callname, '*');
NCB.ncb_buffer := @ADAPTER;
NCB.ncb_length := SizeOf(ADAPTER);
cRC := NetBios(@NCB);
// Convert it to string
strTemp := '';
For intIdx := 0 To 5 Do
strTemp := strTemp + InttoHex(Integer(ADAPTER.adapter_address[in
tIdx]),2);
Result := strTemp;
Finally
End;
End;
End.
我在几台机器上试过用0,都可以取出正确的MAC地址,但是是否任何机器都可以用0呢?
是否一定要装了NetBIOS协议的机子才可以用这种方法取MAC地址呢?
uses Nb30
Function NBGetAdapterAddress(a:integer) : String;
Implementation
{$R *.DFM}
Procedure TForm1.Button1Click(Sender : TObject);
Begin
label1.Caption:=NBGetAdapterAddress(StrtoInt(Edit1.Text));
End;
Function NBGetAdapterAddress(a:Integer) : String;
Var
NCB : TNCB; // Netbios control block //NetBios控制块
ADAPTER : TADAPTERSTATUS; // Netbios adapter status//取网卡状态
LANAENUM : TLANAENUM; // Netbios lana
intIdx : Integer; // Temporary work value//临时变量
cRC : Char; // Netbios return code//NetBios返回值
strTemp : String; // Temporary string//临时变量
Begin
// Initialize
Result := '';
Try
// Zero control blocl
ZeroMemory(@NCB, SizeOf(NCB));
// Issue enum command
NCB.ncb_command := Chr(NCBENUM);
cRC := NetBios(@NCB);
// Reissue enum command
NCB.ncb_buffer := @LANAENUM;
NCB.ncb_length := SizeOf(LANAENUM);
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Reset adapter
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBRESET);
NCB.ncb_lana_num := LANAENUM.lana[a];
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Get adapter address
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBASTAT);
NCB.ncb_lana_num := LANAENUM.lana[a];
StrPCopy(NCB.ncb_callname, '*');
NCB.ncb_buffer := @ADAPTER;
NCB.ncb_length := SizeOf(ADAPTER);
cRC := NetBios(@NCB);
// Convert it to string
strTemp := '';
For intIdx := 0 To 5 Do
strTemp := strTemp + InttoHex(Integer(ADAPTER.adapter_address[in
tIdx]),2);
Result := strTemp;
Finally
End;
End;
End.