如何得到机器的网卡地址?

kangpig 2002-10-30 03:26:35
如何得到机器的网卡地址?
...全文
24 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
角落的青苔 2002-10-31
  • 打赏
  • 举报
回复
这里有篇得到工作组内所有机器的网卡Mac地址
http://freehost13.websamba.com/mosstation/dispbbs.asp?boardID=21&RootID=28&ID=28
cbdiy 2002-10-31
  • 打赏
  • 举报
回复
上面的就是d的
kangpig 2002-10-31
  • 打赏
  • 举报
回复
有没有DELPHI的源码?
zyq2137 2002-10-30
  • 打赏
  • 举报
回复
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information
// for up to 16 NICs
DWORD dwBufLen = sizeof(AdapterInfo); // Save memory size of buffer

DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo
AdapterInfo, // [out] buffer to receive data
&dwBufLen); // [in] size of receive data buffer
assert(dwStatus == ERROR_SUCCESS); // Verify return value is
// valid, no buffer overflow

PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
// current adapter info
do {
PrintMACaddress(pAdapterInfo->Address); // Print MAC address
pAdapterInfo = pAdapterInfo->Next; // Progress through
// linked list
}
while(pAdapterInfo); // Terminate if last adapter
}

具体函数查MSDN和PSDK
chengjian 2002-10-30
  • 打赏
  • 举报
回复
太长了!看不懂!
chechy 2002-10-30
  • 打赏
  • 举报
回复
这个论坛随便搜索一下就有了。这个算法太常见了。下面就是抄来的 。
type
ASTAT =record
adapt:TADAPTERSTATUS ;
NameBuff:array[0..30] of TNameBuffer;
end;
New_byte=array[0..5] of byte;
var

NewByte:New_Byte;
procedure TfrmMain.GetNetCardAddress;
var
ncb:^TNCB;
AdapterList:^TLanaEnum;
ret:Char;
i,K:integer;
Adapter:^ASTAT;
textt:string;
// pAdd:string;
// m_byteAddressMySelf:string;
// m_ctrlThisNetCard:TStrings;
begin
// m_ctrlThisNetCard:=TStringList.Create;
getMem(ncb,sizeof(TNCB));
getMem(AdapterList,sizeof(TLanaEnum));
ncb^.ncb_command:=char(NCBENUM);
Ncb^.ncb_buffer := pchar(AdapterList);
Ncb^.ncb_length := sizeof(AdapterList);
// ret :=Netbios(PNCB(ncb));
Netbios(PNCB(ncb));
if (Ncb^.ncb_retcode<>char(NRC_GOODRET)) then exit;
For I:=0 to ord(AdapterList^.Length) do
begin
getmem(ncb,sizeof(TNCB));
Ncb^.ncb_command := char(NCBRESET);
Ncb^.ncb_lana_num := AdapterList.lana[i];
if (Netbios(PNCB(Ncb)) <> char(NRC_GOODRET)) then exit;

getmem(ncb,sizeof(TNCB));
Ncb^.ncb_command := char(NCBASTAT);
Ncb^.ncb_lana_num := AdapterList.lana[i];
ncb^.ncb_callname:='*';

getMem(Adapter,sizeof(Adapter^));
Ncb^.ncb_buffer := pchar(Adapter);
Ncb^.ncb_length := sizeof(Adapter^);

ret:=Netbios(PNCB(Ncb));

if (ret<> #0) then exit;
for K:=0 to 5 do
if(Adapter^.adapt.adapter_address[K]<>#0)then break;
if(K>=6)then continue;
textt:=format('%.02X %.02X %.02X %.02X %.02X %.02X',
[ord(Adapter^.adapt.adapter_address[0]),
ord(Adapter^.adapt.adapter_address[1]),
ord(Adapter^.adapt.adapter_address[2]),
ord(Adapter^.adapt.adapter_address[3]),
ord(Adapter^.adapt.adapter_address[4]),
ord(Adapter^.adapt.adapter_address[5])]);
if(m_ctrlThisNetCard.items.IndexOf(textt)=LB_ERR)then
m_ctrlThisNetCard.items.Add(textt);
end;

end;

function TfrmMain.HextoDec(const Hex: string): integer;
var
I:integer;
C:char;
Value:integer;
begin
value:=0;
For I:=1 to Length(Hex) do
begin
C:=Hex[I];
if(C>='A') and (C<='F')then
value:=Value*10+(ord(C)-ord('A')+10)
else
Value:=Value*10+(ord(C)-ord('0'));
end;
result:=Value;
end;
function TfrmMain.SetStringtobyte(var NewByte: New_byte;
const SourceStr: string): boolean;
var
str,tmp:string;
start,I:integer;
begin
try
For I:=0 to 5 do
NewByte[I]:=0;
tmp:=Uppercase(SourceStr+' ');
for I:=0 to 5 do
begin
start:=pos(' ',tmp);
inc(start,-1);
str:=copy(tmp,0,start);
NewByte[I]:=HextoDec(str);
tmp:=copy(tmp,start+1,length(tmp)-start);
tmp:=trimLeft(tmp);
end;
result:=True;
except
result:=False;
end;
end;

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧