各位,请问如何获取网卡的MAC地址。最好给段代码。
解决方案 »
- 多线程调用COM对象
- 关于office连接的 TWordApplication 问题!急
- 谁有DevExpress QuantumGrid4.0和delphi sp2?
- 高分求一解决方案,分布式系统,超难,顶者有分,分不够可在加
- ?请问有什么比较好的方法用ado的控件在一个数据库中创建一个表?
- 如何把20020101转变成日期型啊?
- 请问大家发送Tcp数据包是不是一定要两个应用程序,一个是发包的客户端一个是收包的服务端
- 程序员怎么对待客户在软件完成以后又要求添加的需求
- delphi真的不如PB吗?请各位大吓积极讨论这个问题?
- 怎样为服务器端的SQL SERVER增加用户
- 我想在报表中按品名分类,并分别按分类累计其数量,我在报表中添加了QRGROUP 及指定某QRband为其GROUP FOOTER,可是现在累计的都是所有的
- shellapi调用MS DOS 后怎么的到在dos中敲了那些命令呢???
unit Main;
interfaceusesSysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Nb, ExtCtrls;typeTForm1 = class(TForm)Panel1: TPanel;Memo1: TMemo;Panel2: TPanel;Button1: TButton;procedure Button1Click(Sender: TObject);procedure FormCreate(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.DFM} {---------------------------------------------}{ enumerate the lana's - works only on WIN32 }{---------------------------------------------}function NbLanaEnum: TLana_Enum;varNCB: TNCB;L_Enum: TLana_Enum;RetCode: Word;begin{$IFDEF WIN32}FillChar(NCB, SizeOf(NCB), 0);FillChar(L_Enum, SizeOf(TLana_Enum), 0);NCB.Command := NCB_ENUM;NCB.Buf := @L_Enum;NCB.Length := Sizeof(L_Enum);RetCode := NetBiosCmd(NCB);if RetCode <> NRC_GOODRET then beginL_Enum.Length := 0;L_Enum.Lana[0] := Byte(RetCode);end;{$ELSE} { not supported for WIN16, fake LANA 0 }L_Enum.Length := 1;L_Enum.Lana[0] := 0;{$ENDIF}Result := L_Enum;end;{----------------------------------------}{ Reset the lana - don't for WIN16 ! }{----------------------------------------}function NbReset(l: Byte): Word;varNCB: TNCB;begin{$IFNDEF WIN32} { will reset all your connections for WIN1 6 }Result := NRC_GOODRET; { so just fake a reset for Win16 }{$ELSE}FillChar(NCB, SizeOf(NCB), 0);NCB.Command := NCB_RESET;NCB.Lana_Num := l;Result := NetBiosCmd(NCB);{$ENDIF}end;{----------------------------------------}{ return the MAC address of an interface }{ in the form of a string like : }{ 'xx:xx:xx:xx:xx:xx' }{ using the definitions in nb.pas }{----------------------------------------}function NbGetMacAddr(LanaNum: Integer): String;varNCB: TNCB;AdpStat: TAdpStat;RetCode: Word;beginFillChar(NCB, SizeOf(NCB), 0);FillChar(AdpStat, SizeOf(AdpStat), 0);NCB.Command := NCB_ADPSTAT;NCB.Buf := @AdpStat;NCB.Length := Sizeof(AdpStat);FillChar(NCB.CallName, Sizeof(TNBName), $20);NCB.CallName[0] := Byte('*');NCB.Lana_Num := LanaNum;RetCode := NetBiosCmd(NCB);if RetCode = NRC_GOODRET then beginResult := Format('%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x',[AdpStat.ID[0],AdpStat.ID[1],AdpStat.ID[2],AdpStat.ID[3],AdpStat.ID[4],AdpStat.ID[5]]);end else beginResult := '??:??:??:??:??:??';end;end; procedure TForm1.Button1Click(Sender: TObject);beginClose;end;procedure TForm1.FormCreate(Sender: TObject);varL_Enum : TLana_Enum;RetCode: Word;i: Integer;beginL_Enum := NbLanaEnum; { enumerate lanas for WI N NT }if L_Enum.Length = 0 then beginButton1.Caption := Format('LanaEnum err=%2.2x', [L_Enum.Lana[0]]); exit;end;for i := 0 to (L_Enum.Length - 1)do begin { for every lana found }RetCode := NbReset(L_Enum.Lana[i]); { Reset lana for WIN NT }if RetCode <> NRC_GOODRET then beginButton1.Caption := Format('Reset Lana %d err=%2.2x',[i, RetCode ]);exit;end;{ Get MAC Address }Memo1.Lines.Add(Format('Lana %x = %s', [L_Enum.Lana[i], NbGetMacAd dr(i)]));end;Button1.Caption := 'Stop';end;end.—————————————————————————————————— -
留个信箱发给你
,发完后请通知一声。再次谢过!
簡介:
function TForm1.NBGetAdapterAddress(a: integer): String;
//a指定多個網卡適配器中的哪一個0,1,2...
Var
NCB:TNCB; // Netbios control block file://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;最後別忘了uses nb30.pas
經測試,98,2000下皆可用
發表人 - ddy 於 2002/11/23 23:57:24
在iphlpapi.dll里面有一个函数:GetAdaptersInfo()
好像是干这个用的。说明如下:GetAdaptersInfoThe GetAdaptersInfo function retrieves adapter information for the local computer.DWORD GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, // buffer to receive dataPULONG pOutBufLen // size of data returned);ParameterspAdapterInfo[out] Pointer to a buffer that, , receives a linked list of IP_ADAPTER_INFO structures.pOutBufLen[in] Pointer to a ULONG variable that specifies the size of the buffer pointed to by the pAdapterInfo parameter. If this size is insufficient to hold the adapter information, GetAdaptersInfo fills in this variable with the required size, and returns an error code of ERROR_BUFFER_OVERFLOW.Return ValuesIf the function succeeds, the return value is ERROR_SUCCESS.If the function fails, the return value is one of the following error codes.Value MeaningERROR_BUFFER_OVERFLOW The buffer size indicated by the pOutBufLen parameter is too small to hold the adapter information. The pOutBufLen parameter points to the required size.ERROR_INVALID_PARAMETER The pOutBufLen parameter is NULL, or the calling process does not have read/write access to the memory pointed to by pOutBufLen, or the calling process does not have write access to the memory pointed to by the pAdapterInfo parameter.ERROR_NO_DATA No adapter information exists for the local computer.ERROR_NOT_SUPPORTED GetAdaptersInfo is not supported by the operating system running on the local computer.Other If the function fails, use FormatMessage to obtain the message string for the returned error. RequirementsWindows NT/2000: Requires Windows 2000.Windows 95/98: Requires Windows 98.Header: Declared in Iphlpapi.h.//没有Library: Use Iphlpapi.lib.//没有 IP_ADAPTER_INFOThe IP_ADAPTER_INFO structure contains information about a particular network adapter on the local computer.typedef struct _IP_ADAPTER_INFO {struct _IP_ADAPTER_INFO* Next;DWORD ComboIndex;char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];UINT AddressLength;BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];DWORD Index;UINT Type;UINT DhcpEnabled;PIP_ADDR_STRING CurrentIpAddress;IP_ADDR_STRING IpAddressList;IP_ADDR_STRING GatewayList;IP_ADDR_STRING DhcpServer;BOOL HaveWins;IP_ADDR_STRING PrimaryWinsServer;IP_ADDR_STRING SecondaryWinsServer;time_t LeaseObtained;time_t LeaseExpires;} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;MembersNextPointer to the next adapter in the linked list of adapters.ComboIndexThis member is unused.AdapterName[MAX_ADAPTER_NAME_LENGTH + 4]Specifies the name of the adapter.Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4]Specifies a description for the adapter.AddressLengthSpecifies the length of the hardware address for the adapter.Address[MAX_ADAPTER_ADDRESS_LENGTH]Specifies the hardware address for the adapter. //这个是不是你想要的?IndexSpecifies the adapter index.TypeSpecifies the adapter type.DhcpEnabledSpecifies whether dynamic host configuration protocol (DHCP) is enabled for this adapter.CurrentIpAddressSpecifies the current IP address for this adapter.IpAddressListSpecifies the list of IP addresses associated with this adapter.GatewayListSpecifies the IP address of the default gateway for this adapter.DhcpServerSpecifies the IP address of the DHCP server for this adapter.HaveWinsSpecifies whether this adapter uses Windows Internet Name Service (WINS).PrimaryWinsServerSpecifies the IP address of the primary WINS server.SecondaryWinsServerSpecifies the IP address of the secondary WINS server.LeaseObtainedSpecifies the time when the current DHCP lease was obtained.LeaseExpiresSpecifies the time when the current DHCP lease will expire.RequirementsWindows NT/2000: Requires Windows 2000.Windows 95/98: Requires Windows 98.Header: Declared in Iptypes.h.