怎样读取一台机子的网卡id?(200分)

  • 主题发起人 主题发起人 crazyking
  • 开始时间 开始时间
C

crazyking

Unregistered / Unconfirmed
GUEST, unregistred user!
最好有详细的实现代码。(另外,不同的网卡id号会相同吗?)
 
是不是网卡的mac地址呀?
 
MAC地址不会重复的。
terry_lzs (2001-5-29 12:50:00)
--------------------------------------------------------------------
获得MAC地址
unit Unit1;

interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,nb30;
type
PASTAT = ^TASTAT;
TASTAT = record
adapter : TAdapterStatus;
name_buf : TNameBuffer;
end;

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
function Getmac:string;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin

label1.caption:=Getmac;
end;

function TForm1.Getmac:string;
var
ncb : TNCB;
s:string;
adapt : TASTAT;
lanaEnum : TLanaEnum;
i, j, m : integer;
strPart, strMac : string;
begin

FillChar(ncb, SizeOf(TNCB), 0);
ncb.ncb_command := Char(NCBEnum);
ncb.ncb_buffer := PChar(@lanaEnum);
ncb.ncb_length := SizeOf(TLanaEnum);
s:=Netbios(@ncb);
for i := 0 to integer(lanaEnum.length)-1do

begin

FillChar(ncb, SizeOf(TNCB), 0);
ncb.ncb_command := Char(NCBReset);
ncb.ncb_lana_num := lanaEnum.lana;
Netbios(@ncb);
Netbios(@ncb);
FillChar(ncb, SizeOf(TNCB), 0);
ncb.ncb_command := Chr(NCBAstat);
ncb.ncb_lana_num := lanaEnum.lana;
ncb.ncb_callname := '* ';
ncb.ncb_buffer := PChar(@adapt);
ncb.ncb_length := SizeOf(TASTAT);
m:=0;
if (Win32Platform = VER_PLATFORM_WIN32_NT) then

m:=1;
if m=1 then

begin

if Netbios(@ncb) = Chr(0) then

strMac := '';
for j := 0 to 5do

begin

strPart := IntToHex(integer(adapt.adapter.adapter_address[j]), 2);
strMac := strMac + strPart + '-';
end;

SetLength(strMac, Length(strMac)-1);
end;

if m=0 then

if Netbios(@ncb) <> Chr(0) then

begin

strMac := '';
for j := 0 to 5do

begin

strPart := IntToHex(integer(adapt.adapter.adapter_address[j]), 2);
strMac := strMac + strPart + '-';
end;

SetLength(strMac, Length(strMac)-1);
end;

end;

result:=strmac;
end;

end.


 
多谢多谢,不过我delphi很菜。想知道这段代码里用没用到delphi特有的一些控件,也
就是说能不能改写成pb或者vb代码?谢谢!
 
应该可以,上面都是一些结构和API
 
偶不会啊!谁能把它改成pb的?多谢!
 
http://pbsite.nease.net/download/download.htm
http://pbsite.nease.net/download/getmac.zip
 
虽然很想要pb代码,不过最起码是能用了!多谢!给分!
 
zw84611:
请教两个问题!
1、为什么用你的这个取网卡MAC地址的程序在Win2k下要安装NetBEUI协议呢?
2、为何读取出的MAC地址有时正常,但重启电脑后再读取MAC地址会变成完全不同的另一个?
如果能帮我解决这些问题,不胜感激!为表谢意,我会另外再送分!谢谢!
 

Similar threads

后退
顶部