如何自己写代码找出自己所用的网卡的MAC(50分)

  • 主题发起人 主题发起人 shayang
  • 开始时间 开始时间
S

shayang

Unregistered / Unconfirmed
GUEST, unregistred user!
如何自己写代码找出自己所用的网卡的MAC
 
function GetMACAddress(a:integer):string;
var
crc:char;
ncb:tncb;
adapter:tadapterstatus;
lanaenum:tlanaenum;
intidx:integer;
strtemp:string;
begin
result:='';
try
zeromemory(@ncb,sizeof(ncb));
ncb.ncb_command:=chr(ncbenum);
crc:=netbios(@NCB);
ncb.ncb_buffer:=Pchar(@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:=Pchar(@adapter);
ncb.ncb_length:=sizeof(adapter);
crc:=netbios(@NCB);
strtemp:='';
for intidx:=0 to 5 do
strtemp:=strtemp+inttohex(integer(adapter.adapter_address[intidx]),2);
result:=strtemp;
finally
end;
end;
 
function GetMACAddress(a:integer):string;//a=0第一塊網卡,a=1第二塊網卡
var
crc:char;
ncb:tncb;
adapter:tadapterstatus;
lanaenum:tlanaenum;
intidx:integer;
strtemp:string;
begin
result:='';
try
zeromemory(@ncb,sizeof(ncb));
ncb.ncb_command:=chr(ncbenum);
crc:=netbios(@NCB);
ncb.ncb_buffer:=Pchar(@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:=Pchar(@adapter);
ncb.ncb_length:=sizeof(adapter);
crc:=netbios(@NCB);
strtemp:='';
for intidx:=0 to 5 do
strtemp:=strtemp+inttohex(integer(adapter.adapter_address[intidx]),2);
result:=strtemp;
finally
end;
end;
 
ncb:tncb;
adapter:tadapterstatus;
lanaenum:tlanaenum;
这三个类出自那里
 
这三个类出自NB30中.
你要在USES中加入NB30就OK了.
我是在DELPHI6中使用.如是其它版本的你可能要更改一下了.
 
还在用NB30????上个世纪中叶的破烂技术了!!
可以采用三种方式:
1、98下,采用GUID;
2、2000,XP下,通过ARP或UDP
举个例子:
用ARP,FIPAddr=你的网卡捆绑的IP
function TForm1.GetMacByIP(FIPAddr: string): string;
var
dwResult: DWord;
ulIPAddr: DWord;
ulMacAddr: array[0..5] of Byte;
ulAddrLen: ULONG;
begin
ulIPAddr := INet_Addr(PChar(FIPAddr));

if ulIPAddr = INADDR_NONE then
exit;
ulAddrLen := 6;
dwResult := SendARP(ulIPAddr, 0, @ulMacAddr, @ulAddrLen);

if dwResult = 0 then
result := (IntToHex(ulMacAddr[0], 2) + ':' +
IntToHex(ulMacAddr[1], 2) + ':' +
IntToHex(ulMacAddr[2], 2) + ':' +
IntToHex(ulMacAddr[3], 2) + ':' +
IntToHex(ulMacAddr[4], 2) + ':' +
IntToHex(ulMacAddr[5], 2))
else
result := '';
end;
 
INet_Addr不行,在哪个包中
 
inet_addr在winsock单元,但是masm你的sendARP在哪里啊?
 
呵呵呵...拉下了,对不起!补上!
...
implementation
function inet_addr(const cp: PChar): DWord; stdcall; external 'WS2_32.DLL' name 'inet_addr';
function SendARP(const DestIP: DWord;
const SrcIP: DWord;
const pMacAddr: Pointer;
const PhyAddrLen: PULONG): DWord; stdcall; external 'IPHLPAPI.dll' name 'SendARP';

{$R *.dfm}
function TForm1.GetMacByIP(FIPAddr: string): string;
...
 
masm 强
你的还可以远程取网卡MAC地址^-^
 
接受答案了.
 
后退
顶部