uses ....Winsock,NB30....
...........type
PMACAddress = ^TMACAddress;
TMACAddress = array[0..5] of Byte; //六位网卡地址function GetMACAddress(LanaNum: Byte; MACAddress: PMACAddress): Byte;var
AdapterStatus: PAdapterStatus;
StatNCB: PNCB;begin
New(StatNCB);
ZeroMemory(StatNCB, SizeOf(TNCB));
StatNCB.ncb_length := SizeOf(TAdapterStatus) + 255 * SizeOf(TNameBuffer);
GetMem(AdapterStatus, StatNCB.ncb_length);
try
with StatNCB^ do
begin
ZeroMemory(MACAddress, SizeOf(TMACAddress));
ncb_buffer := PChar(AdapterStatus);
ncb_callname := '* ' + #0;
ncb_lana_num := Char(LanaNum);
ncb_command := Char(NCBASTAT);
NetBios(StatNCB);
Result := Byte(ncb_cmd_cplt);
if Result = NRC_GOODRET then
MoveMemory(MACAddress, AdapterStatus, SizeOf(TMACAddress));
end;
finally
FreeMem(AdapterStatus);
Dispose(StatNCB);
end;
end;function GetLanaEnum(LanaEnum: PLanaEnum): Byte;
var
LanaEnumNCB: PNCB;begin
New(LanaEnumNCB);
ZeroMemory(LanaEnumNCB, SizeOf(TNCB));
try
with LanaEnumNCB^ do
begin
ncb_buffer := PChar(LanaEnum);
ncb_length := SizeOf(TLanaEnum);
ncb_command := Char(NCBENUM);
NetBios(LanaEnumNCB);
Result := Byte(ncb_cmd_cplt);
end;
finally
Dispose(LanaEnumNCB);
end;
end;//在程序中显示网卡地址
New(MACAddress);
try
RetCode := GetMACAddress(0, MACAddress);
if RetCode = NRC_GOODRET then
begin
label5.caption := '你的网卡地址是:'+Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
[MACAddress[0], MACAddress[1], MACAddress[2],
MACAddress[3], MACAddress[4], MACAddress[5]]);
end;
finally
Dispose(MACAddress);
end;
...........type
PMACAddress = ^TMACAddress;
TMACAddress = array[0..5] of Byte; //六位网卡地址function GetMACAddress(LanaNum: Byte; MACAddress: PMACAddress): Byte;var
AdapterStatus: PAdapterStatus;
StatNCB: PNCB;begin
New(StatNCB);
ZeroMemory(StatNCB, SizeOf(TNCB));
StatNCB.ncb_length := SizeOf(TAdapterStatus) + 255 * SizeOf(TNameBuffer);
GetMem(AdapterStatus, StatNCB.ncb_length);
try
with StatNCB^ do
begin
ZeroMemory(MACAddress, SizeOf(TMACAddress));
ncb_buffer := PChar(AdapterStatus);
ncb_callname := '* ' + #0;
ncb_lana_num := Char(LanaNum);
ncb_command := Char(NCBASTAT);
NetBios(StatNCB);
Result := Byte(ncb_cmd_cplt);
if Result = NRC_GOODRET then
MoveMemory(MACAddress, AdapterStatus, SizeOf(TMACAddress));
end;
finally
FreeMem(AdapterStatus);
Dispose(StatNCB);
end;
end;function GetLanaEnum(LanaEnum: PLanaEnum): Byte;
var
LanaEnumNCB: PNCB;begin
New(LanaEnumNCB);
ZeroMemory(LanaEnumNCB, SizeOf(TNCB));
try
with LanaEnumNCB^ do
begin
ncb_buffer := PChar(LanaEnum);
ncb_length := SizeOf(TLanaEnum);
ncb_command := Char(NCBENUM);
NetBios(LanaEnumNCB);
Result := Byte(ncb_cmd_cplt);
end;
finally
Dispose(LanaEnumNCB);
end;
end;//在程序中显示网卡地址
New(MACAddress);
try
RetCode := GetMACAddress(0, MACAddress);
if RetCode = NRC_GOODRET then
begin
label5.caption := '你的网卡地址是:'+Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
[MACAddress[0], MACAddress[1], MACAddress[2],
MACAddress[3], MACAddress[4], MACAddress[5]]);
end;
finally
Dispose(MACAddress);
end;
解决方案 »
- 用TImage控件做背景图片 ,如何让绘制的图像显示在上面
- DELPHI程序能不能在IMAGE控件上让鼠标拉的范围内也有一个框框区域(如图)?而且在画的时候不能消失,且可以看到画的内容,而且前面画的不能消失
- 求sql语句写法,急急!!!!!!!!!!11
- 图象识别的问题!大家都来帮帮忙!
- 实际运用中的关于读卡问题
- Delphi达人进-怎么把StringGrid里的数据写到数据库中的一个表里?
- 小弟也是一个delphi迷,希望大家能给我指导,http://delphiicq.126.com
- 大家给意见——工资项目的动态变化
- 关于多线程的一个问题,suspend之后再,resume为什么挂起的线程不能继续执行
- 关于“Index is out of date”的错误
- 用什么方法可以实现在一个输入框中时间的形式为“年-月-日-小时-分-秒”
- 数据库中的主键序号如何按类重整?
uses NB30; function GetMACAdress: string;
var
NCB: PNCB;
Adapter: PAdapterStatus; URetCode: PChar;
RetCode: char;
I: integer;
Lenum: PlanaEnum;
_SystemID: string;
TMPSTR: string;
begin
Result := '';
_SystemID := '';
Getmem(NCB, SizeOf(TNCB));
Fillchar(NCB^, SizeOf(TNCB), 0); Getmem(Lenum, SizeOf(TLanaEnum));
Fillchar(Lenum^, SizeOf(TLanaEnum), 0); Getmem(Adapter, SizeOf(TAdapterStatus));
Fillchar(Adapter^, SizeOf(TAdapterStatus), 0); Lenum.Length := chr(0);
NCB.ncb_command := chr(NCBENUM);
NCB.ncb_buffer := Pointer(Lenum);
NCB.ncb_length := SizeOf(Lenum);
RetCode := Netbios(NCB); i := 0;
repeat
Fillchar(NCB^, SizeOf(TNCB), 0);
Ncb.ncb_command := chr(NCBRESET);
Ncb.ncb_lana_num := lenum.lana[I];
RetCode := Netbios(Ncb); Fillchar(NCB^, SizeOf(TNCB), 0);
Ncb.ncb_command := chr(NCBASTAT);
Ncb.ncb_lana_num := lenum.lana[I];
// Must be 16
Ncb.ncb_callname := '* '; Ncb.ncb_buffer := Pointer(Adapter); Ncb.ncb_length := SizeOf(TAdapterStatus);
RetCode := Netbios(Ncb);
//---- calc _systemId from mac-address[2-5] XOR mac-address[1]...
if (RetCode = chr(0)) or (RetCode = chr(6)) then
begin
_SystemId := IntToHex(Ord(Adapter.adapter_address[0]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[1]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[2]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[3]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[4]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[5]), 2);
end;
Inc(i);
until (I >= Ord(Lenum.Length)) or (_SystemID <> '00-00-00-00-00-00');
FreeMem(NCB);
FreeMem(Adapter);
FreeMem(Lenum);
GetMacAdress := _SystemID;
end; //使用例子procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := GetMACAdress;
end;
var Command:String;
tempResult:String;
begin
Command:='Command.com /c nbtstat -a '+Name+' >temp.txt';
WinExec(Pchar(Command),SW_HIDE);
Sleep(1000);
Memo1.Lines.LoadFromFile('temp.txt');
tempResult:=Memo1.Lines[Memo1.Lines.Count-1];
Memo1.Lines.Clear;
if tempResult='Host not found.' then Result:='Error!'
else
begin
tempResult:=Copy(tempResult,15,17);
Result:=ReplaceText(tempResult,'-','');
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := GetMacsFromName('计算机名');
end;