delphi怎么获取本机网卡号?(50)

  • 主题发起人 主题发起人 zhongjun762
  • 开始时间 开始时间
Z

zhongjun762

Unregistered / Unconfirmed
GUEST, unregistred user!
delphi怎么获取本机网卡号?可以的话发一个DEMO到我的邮箱吧,zhongjun762@163.com..分数另计
 
问题已经解决了
 
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; const MAX_ADAPTER_NAME_LENGTH = 256; MAX_ADAPTER_DESCRIPTION_LENGTH = 128; MAX_ADAPTER_ADDRESS_LENGTH = 8;type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;Type TIPAddressString = Array[0..4*4-1] of Char; PIPAddrString = ^TIPAddrString; TIPAddrString = Record Next : PIPAddrString; IPAddress : TIPAddressString; IPMask : TIPAddressString; Context : Integer;End; PIPAdapterInfo = ^TIPAdapterInfo; TIPAdapterInfo = Record { IP_ADAPTER_INFO } Next : PIPAdapterInfo; ComboIndex : Integer; AdapterName : Array[0..MAX_ADAPTER_NAME_LENGTH+3] of Char; Description : Array[0..MAX_ADAPTER_DESCRIPTION_LENGTH+3] of Char; AddressLength : Integer; Address : Array[1..MAX_ADAPTER_ADDRESS_LENGTH] of Byte; Index : Integer; _Type : Integer; DHCPEnabled : Integer; CurrentIPAddress : PIPAddrString; IPAddressList : TIPAddrString; GatewayList : TIPAddrString;End;var Form1: TForm1;gatewaystr:string;strlen:integer;implementation{$R *.dfm}Function GetAdaptersInfo(AI : PIPAdapterInfo; Var BufLen : Integer) : Integer;StdCall; External 'iphlpapi.dll' Name 'GetAdaptersInfo';Function MACToStr(ByteArr : PByte; Len : Integer) : String;BeginResult := ''; While (Len > 0) do Begin Result := Result+IntToHex(ByteArr^,2)+'-'; ByteArr := Pointer(Integer(ByteArr)+SizeOf(Byte)); Dec(Len); End; SetLength(Result,Length(Result)-1); { remove last dash }End;Function GetAddrString(Addr : PIPAddrString) : String; Begin Result := ''; While (Addr <> nil) do Begin Result := Result+'A: '+Addr^.IPAddress+' M: '+Addr^.IPMask+#13; Addr := Addr^.Next; End;End;procedure TForm1.Button1Click(Sender: TObject);var AI,Work : PIPAdapterInfo; Size : Integer; Res : Integer;begin Size := 5120; GetMem(AI,Size); work:=ai; Res := GetAdaptersInfo(AI,Size); If (Res <> ERROR_SUCCESS) Then Begin SetLastError(Res); End; //网卡地址: memo1.Lines.Add ('Adapter address: '+MACToStr(@Work^.Address,Work^.AddressLength)); repeat //本机IP地址: memo1.Lines.add('IP addresses: '+GetAddrString(@Work^.IPAddressList)); //网关地址: gatewaystr:=work^.GatewayList.IPAddress; memo1.Lines.Add('gateway address:'+gatewaystr); work:=work^.Next ; until (work=nil);end;end.
 
高手啊~~哈哈~~
 
测试通过,但有不明白的地方。
 
我看了,还没有验证。
 
多人接受答案了。
 

Similar threads

回复
0
查看
576
不得闲
回复
0
查看
978
不得闲
回复
0
查看
782
不得闲
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
875
DelphiTeacher的专栏
D
后退
顶部