怎得到WIN2K下的准确有效MAC地址?(100分)

  • 主题发起人 主题发起人 飘叶
  • 开始时间 开始时间

飘叶

Unregistered / Unconfirmed
GUEST, unregistred user!
WIN98、WINME、WIN XP下都可以得到网卡唯一的MAC地址,但在WIN2K下都是得到多个不同的MAC地址,是不是WIN2K的BUG?怎么样才能得到准确有效的那个真实MAC
 
//应该要安装了NetBui(netbios)协议才行。

uses nb30;

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[intIdx]),2);
Result := strTemp;
Finally
End;
End;

procedure TForm1.Button2Click(Sender: TObject);
begin
caption := NBGetAdapterAddress(0)
end;
 
照样不行!
用你的程序XP与98下都有得到正常的MAC:0020ED14F090
但2K下却是:444553547776

问题就出在 NBGetAdapterAddress(0)
改变参数0为其它值,总可以找出到真正的MAC,但关键是哪个参数值才能得出真正的MAC?
而且这个值在不同的机器是不同的。
 
奇怪,我也是win2k,怎么没有这个问题。
 
//Win2k下可以这样:

uses WinSock;
{$R *.DFM}

function SendARP(const DestIP, SrcIP: Cardinal; pMacAddr: PULONG; var PhyAddrLen: ULONG): DWORD; stdcall;external 'iphlpapi.dll';

function GetIPAddress: string;
var
phoste:PHostEnt;
Buffer:array[0..100] of char;
WSAData:TWSADATA;
begin
result:='';
if WSASTartup($0101, WSAData) <> 0 then exit;
GetHostName(Buffer,Sizeof(Buffer));
phoste:=GetHostByName(buffer);
if phoste = nil then
begin
result:='127.0.0.1';
end
else
result:=StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));
WSACleanup;
end;

procedure TForm1.Button1Click(Sender: TObject);
var MacAddr:array[1..6]of byte;
MacAddrLen:ULONG;
ret:DWORD;
begin
MacAddrLen:=sizeof(MacAddr);
ret:=SendARP(inet_addr(pChar(GetIPAddress)),0,@MacAddr,MacAddrLen);
if ret=0 then
Memo1.Lines.add('IP: '+GetIPAddress+' MAC: '+format('%.2x.%.2x.%.2x.%.2x.%.2x.%.2x',[MacAddr[1],MacAddr[2],MacAddr[3],MacAddr[4],MacAddr[5],MacAddr[6]]))
else ShowMessage('no ack!');
end;
 
解决了,谢谢
 
后退
顶部