通过程序获得本机的MAC地址
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控制块
ADAPTER : TADAPTERSTATUS; //取网卡状态
LANAENUM : TLANAENUM; // Netbios lana
intIdx : Integer; //临时变量
cRC : Char; //NetBios返回值
strTemp : String; //临时变量
Begin
//初始化
Result := '';
Try
// 内存清零
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;
// 初始化网卡地址
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;
// 得到网卡地址
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);
//将网卡地址转换成某种格式字符串
strTemp := '';
For intIdx := 0 To 5 Do
strTemp := strTemp + InttoHex(Integer(ADAPTER.adapter_address[in
tIdx]),2);
Result := strTemp;
Finally
End;
End;
End.