着急!!如何判别机器中有几块网卡?(100分)

  • 主题发起人 主题发起人 DelphiBugs
  • 开始时间 开始时间
D

DelphiBugs

Unregistered / Unconfirmed
GUEST, unregistred user!
大家都知道,拨号适配器也有MAC地址,
但其不是“真正“的网卡,我现在想要知道的是一台机器中真正的网卡数量,请问如何实现?
 
把机箱拆开看看有没有网卡,再看看主板上有没有集成(通过主板说明书)。
 
用nbtstat.exe试试!
 
如果所有网卡都已经驱动,可以读取注册表HKEY_LOCAL_MACHINE下
system//currentcontrolset//services//class//net,可取得各适配器的描述.[:)]
 
各位仁兄:小弟想将在系统中的网卡一一列出,不包括其他非硬件虚拟设备。而且要求不仅在
Windows98下,而且要在Win2000(NT)下也要均能实现。
各位高手,如有源码最好,希望给小弟一份,小弟不甚感激。
 
关于Win 2K修改MAC

REGEDIT4
[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Class/{4D36E972-E325-11CE-BFC1-08002BE10318}/0000]
"networkaddress"="444553540000"
[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Class/{4D36E972-E325-11CE-BFC1-08002BE10318}/0000/Ndi/params/networkaddress]
"default"="444553540000"
"paramdesc"="MAC Address"


网卡编号代表网卡型号,不一定是0000,究竟是什么编号,可以这样查找:
运行/winnt/regedit.exe,找到注册表项
[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Class/{4D36E972-E325-11CE-BFC1-08002BE10318}/0000]
右边栏目有一字符串值"DriverDesc",它的值即是网卡型号,看是不是你的网卡;
再找
[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Class/{4D36E972-E325-11CE-BFC1-08002BE10318}/0001]
直到找到你的网卡,记下网卡的编号:一定是000X(X是整数),如0007
然后将上述Win 2K注册表中的"/0000"改为相应的"/0007"(有两处),再进行其它操作.
恢复原始网卡MAC地址: 请删除字符串值"networkaddress"和主键"networkaddress".


NT下修改MAC:
REGEDIT4
[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/HPHX1/Parameters]
"NetworkAddress"="131353540000"
注意:上述注册表文件中HPHX1是具体的网卡型号,各位网友请根据自已的型号修改,修改方法:
 在NT的窗口DOS下运行:
 ipconfig -all
 它将显示网卡的型号和MAC(物理)地址等信息,注意看Ethernet adapter 后面的字符串就是网卡型号。
如果要恢复NT下网卡的原始MAC地址,请将字符串主键"networkaddress"的值清空

 
谢谢zhihuali兄,小弟还是有些不明,怎样读出网卡的品牌名等及网卡的一些详细信息。如
方便请给出代码。谢谢,在这里先送您50分,本人理解后,再重谢!!
 
HOWTO: Use Winsock to Enumerate Addresses

Q129315


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Win32 Software Development Kit (SDK) for Windows NT, versions 3.5, 3.51

--------------------------------------------------------------------------------


SUMMARY
Winsock offers several ways to obtain addressing information for TCP/IP-based machines. This article demonstrates how to obtain address information for IPX and NetBIOS under Windows NT.



MORE INFORMATION

Method One
AF_IPX
You can use this sample to give an IPX address:
Sample Code

#include <winsock.h>
#include <wsipx.h>
#include <wsnwlink.h>

#include <stdio.h>

void main()
{
WSADATA wsaData;
int cAdapters, res,
cbOpt = sizeof( cAdapters ),
cbAddr = sizeof( SOCKADDR_IPX );

SOCKET s;
SOCKADDR_IPX Addr;

if (WSAStartup(0x0101, &amp;wsaData))
{
printf("WSAStartup failed %s/n", WSAGetLastError());
return;
}

// Create IPX socket.
s = socket( AF_IPX, SOCK_DGRAM, NSPROTO_IPX );

if(s==INVALID_SOCKET)
printf("Error: %u/n", WSAGetLastError());

// Socket must be bound prior to calling IPX_MAX_ADAPTER_NUM.
memset( &amp;Addr, 0, sizeof( Addr ));
Addr.sa_family = AF_IPX;
res = bind( s, (SOCKADDR*) &amp;Addr, cbAddr);
if(res != 0)
printf("Error: %u/n", WSAGetLastError());

// Get the number of adapters => cAdapters.
res = getsockopt( (SOCKET) s, NSPROTO_IPX, IPX_MAX_ADAPTER_NUM,
(char *) &amp;cAdapters, &amp;cbOpt );
if(res != 0)
printf("Error: %u/n", WSAGetLastError());
// At this point cAdapters is the number of installed adapters.
while ( cAdapters > 0 )
{
IPX_ADDRESS_DATA IpxData;

memset( &amp;IpxData, 0, sizeof(IpxData));

// Specify which adapter to check.
IpxData.adapternum = cAdapters - 1;
cbOpt = sizeof( IpxData );

// Get information for the current adapter.
res = getsockopt( s, NSPROTO_IPX, IPX_ADDRESS,
(char*) &amp;IpxData, &amp;cbOpt );
if(res != 0)
printf("Error: %u/n", WSAGetLastError());
else
{
// IpxData contains the address for the current adapter.
int i;
printf("Net Number: ");
for (i=0;i<4;i++)
printf("%02X",IpxData.netnum);
printf("/n");
printf("Node Address: ");
for (i=0;i<5;i++)
printf("%02X-",IpxData.nodenum);
printf("%02X/n",IpxData.nodenum);
}

cAdapters--;
}

WSACleanup();
return;
}
AF_NETBIOS
The following sample uses the EnumProtocols() function to give lana numbers for the available NetBIOS transports. Additionally, under Winsock2, the function WSAEnumProtocols() replaces EnumProtocols(); it returns the same information as before, but also includes additional information. With both functions, the key is to take the absolute value of the iProtocol field of either the PROTOCOL_INFO or WSAPROTOCOL_INFO structure, which is the LANA number for that transport.

The PROTOCOL_INFO structure is returned by EnumProtocols(), while WSAEnumProtocols() uses the WSAPROTOCOL_INFO structure. This enumeration does not work under Windows NT 3.5 because of a bug in EnumProtocols(). Winsock 2 is available on Windows NT 4.0 or later.

NOTE: Winsock 2 is also available for Windows 95 and its functionality is built in to Windows 98.

Lastly, the iProtocol value for the transport corresponding to LANA 0 will be 0x80000000. The reason for this is protocol 0 is reserved for internal use.
Sample Code

#include <windows.h>
#include <assert.h>
#include <nspapi.h>

#include <stdio.h>
void main()
{
DWORD cb = 0;
PROTOCOL_INFO *pPI;
BOOL pfLanas[100];

int iRes,
nLanas = sizeof(pfLanas) / sizeof(BOOL);

// Specify NULL for lpiProtocols to enumerate all protocols.
// First, determine the output buffer size.

iRes = EnumProtocols( NULL, NULL, &amp;cb );

// Verify that the expected error was received.
assert( iRes == -1 &amp;&amp; GetLastError() == ERROR_INSUFFICIENT_BUFFER );
if (!cb)
{
printf( "No available NetBIOS transports./n");
return;
}

// Allocate a buffer of the specified size.
pPI = (PROTOCOL_INFO*) malloc( cb );

// Enumerate all protocols.
iRes = EnumProtocols( NULL, pPI, &amp;cb );

// EnumProtocols() lists each lana number twice, once for
// SOCK_DGRAM and once for SOCK_SEQPACKET. Set a flag in pfLanas
// so unique lanas can be identified.

memset( pfLanas, 0, sizeof( pfLanas ));

while (iRes > 0)
{
// Scan protocols looking for AF_NETBIOS.
if ( pPI[--iRes].iAddressFamily == AF_NETBIOS )
// Found one.
pfLanas[ abs(pPI[iRes].iProtocol) ] = TRUE;
}

printf( "Available NetBIOS lana numbers: " );
while( nLanas-- )
if ( pfLanas[nLanas] )
printf( "%d ", nLanas );

printf( "/n" );
free( pPI );
return;
}



AF_APPLETALK
Address enumeration is not meaningful for AF_APPLETALK. On a multi-homed host with routing disabled, only the default adapter is used. If routing is enabled, a single AppleTalk address is used for all installed network adapters.
Method Two
Listed below is an example of how to use the WinSock database APIs to give IP addresses:
Sample Code

#include <windows.h>
#include <winsock.h>
#include <stdio.h>

void main()
{
WSADATA wsaData;
char szHostname[100];
HOSTENT *pHostEnt;
int nAdapter = 0;
struct sockaddr_in sAddr;

if (WSAStartup(0x0101, &amp;wsaData))
{
printf("WSAStartup failed %s/n", WSAGetLastError());
return;
}

gethostname( szHostname, sizeof( szHostname ));
pHostEnt = gethostbyname( szHostname );

while ( pHostEnt->h_addr_list[nAdapter] )
{
// pHostEnt->h_addr_list[nAdapter] is the current address in host
// order.

// Copy the address information from the pHostEnt to a sockaddr_in
// structure.
memcpy ( &amp;sAddr.sin_addr.s_addr, pHostEnt->h_addr_list[nAdapter],
pHostEnt->h_length);

// Output the machines IP Address.
printf("Name: %s/nAddress: %s/n", pHostEnt->h_name,
inet_ntoa(sAddr.sin_addr));

nAdapter++;
}
WSACleanup();
return;

}

Additional query words:

Keywords : kbnetwork kbAPI kbNetBIOS kbNTOS350 kbNTOS351 kbSDKPlatform kbWinsock kbGrpNet
Issue type : kbhowto
Technology :


Last Reviewed: October 15, 1999
&amp;copy; 2001 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
 
procedure TMulticastSocket.LocalIPs(slIPs: TStringList);
var
strLocalHost : string;
pHE : PHostent;
pInAd : PAPInAddr;
saLocal : TSockAddr;
i : integer;
begin
SetLength(strLocalHost, 255);
if GetHostName(PChar(strLocalHost), 254) = SOCKET_ERROR then
Exit;

pHE := GetHostByName(PChar(strLocalHost));
pInAd := PAPInAddr(pHE^.h_addr_list);
saLocal.sin_addr := (pInAd^[0]^);
i := 0;
while True do
begin
slIPs.Add(inet_ntoa(saLocal.sin_addr));
i := i + 1;
if(pInAd^ <> nil) then
saLocal.sin_addr := (pInAd^^) //local host
else
break;
end;
end;
 
谢谢厉害兄,小弟才书浅薄,我还是不太理解你给我的代码,请问第一段代码,好像是枚举
地址,是不是网卡地址?第二段代码就不太清楚了,是不是该问题在Delphi下的实现?如果
你愿意,请您详细的给我说一下,行么?
 
查看IP啊,有几个IP就有几个网卡
 
http://www.lkinfo.net/netcard.rar
 
后退
顶部