怎样得到本机的网卡号??? 怎样得到本机的网卡号??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 到DOS 下运行:ipconfig /all其中的物理地址不知道是不是你想要的网卡号 BOOL bRet = FALSE; NCB ncb; PUCHAR pData; ZeroMemory(&ncb, sizeof(ncb)); pData = (PUCHAR)malloc(sizeof(ADAPTER_STATUS) + 16 * sizeof(NAME_BUFFER)); CopyNetbiosName((char *)&ncb.ncb_callname, szName); ncb.ncb_command = NCBASTAT; ncb.ncb_buffer = (PUCHAR)pData; ncb.ncb_lana_num = 0; ncb.ncb_length = sizeof(ADAPTER_STATUS) + 16 * sizeof(NAME_BUFFER); Netbios(&ncb); CString szAddress; if(ncb.ncb_retcode == NRC_GOODRET) { ADAPTER_STATUS *pStatus = (ADAPTER_STATUS *)pData; UCHAR *pAddress = pStatus->adapter_address; szAddress.Format("%02X%02X%02X%02X%02X%02X", pAddress[0], pAddress[1], pAddress[2], pAddress[3], pAddress[4], pAddress[5]); bRet = TRUE; } else szAddress = "Wrong Name!"; 你在msdn上用howto get mac查 HOWTO: Get the MAC Address for an Ethernet AdapterID: Q118623 --------------------------------------------------------------------------------The information in this article applies to:Microsoft Win32 Software Development Kit (SDK), used with:Microsoft Windows NT, versions 3.1, 3.5, 3.51, 4.0 Microsoft Windows 2000 Microsoft Windows versions 95, 98--------------------------------------------------------------------------------SUMMARYThis article demonstrates how to get the Media Access Control (MAC) address for an ethernet adapter programmatically by using NetBIOS, if your card is bound to NetBIOS. MORE INFORMATIONTo get the Media Access Control (MAC) address for an ethernet adapter programmatically, use the Netbios() NCBASTAT command and provide a "*" as the name in the NCB.ncb_CallName field. This is demonstrated in the sample code below. For computers with multiple network adapters you need to enumerate the LANA numbers and perform the NCBASTAT command on each. Even when you have a single network adapter, it is a good idea to enumerate valid LANA numbers first and perform the NCBASTAT on one of the valid LANA numbers. It is considered bad programming to hardcode the LANA number to 0. In addition, other hardware and software may be assigned their own MAC addresses. For example, a modem can have a MAC address. Also, a RAS client or server can install "dummy" network adapters that correspond to a dialup or serial connection. Normally, these MAC addresses are randomly generated. If an adapter status is called on a LANA that corresponds to one of these adapters when no connection is present, Netbios returns error 0x34 (NRC_ENVNOTDEF) even if a reset was previously performed. With the NetBEUI and IPX transports, the same information can be obtained at a command prompt by using: net config workstation The ID given is the MAC address. The following code enumerates all LANA numbers, performs a reset (NCBREST), and an adapter status (NCBASTAT). Sample Code #include <windows.h> #include <wincon.h> #include <stdlib.h> #include <stdio.h> #include <time.h> typedef struct _ASTAT_ { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff [30]; }ASTAT, * PASTAT; ASTAT Adapter; void main (void) { NCB Ncb; UCHAR uRetCode; char NetName[50]; LANA_ENUM lenum; int i; memset( &Ncb, 0, sizeof(Ncb) ); Ncb.ncb_command = NCBENUM; Ncb.ncb_buffer = (UCHAR *)&lenum; Ncb.ncb_length = sizeof(lenum); uRetCode = Netbios( &Ncb ); printf( "The NCBENUM return code is: 0x%x \n", uRetCode ); for(i=0; i < lenum.length ;i++) { memset( &Ncb, 0, sizeof(Ncb) ); Ncb.ncb_command = NCBRESET; Ncb.ncb_lana_num = lenum.lana[i]; uRetCode = Netbios( &Ncb ); printf( "The NCBRESET on LANA %d return code is: 0x%x \n", lenum.lana[i], uRetCode ); memset( &Ncb, 0, sizeof (Ncb) ); Ncb.ncb_command = NCBASTAT; Ncb.ncb_lana_num = lenum.lana[i]; strcpy( Ncb.ncb_callname, "* " ); Ncb.ncb_buffer = (char *) &Adapter; Ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios( &Ncb ); printf( "The NCBASTAT on LANA %d return code is: 0x%x \n", lenum.lana[i], uRetCode ); if ( uRetCode == 0 ) { printf( "The Ethernet Number on LANA %d is: %02x%02x%02x%02x%02x%02x\n", lenum.lana[i], Adapter.adapt.adapter_address[0], Adapter.adapt.adapter_address[1], Adapter.adapt.adapter_address[2], Adapter.adapt.adapter_address[3], Adapter.adapt.adapter_address[4], Adapter.adapt.adapter_address[5] ); } } } Additional query words: Keywords : kbnetwork kbAPI kbNetBIOS kbNTOS310 kbNTOS350 kbNTOS351 kbSDKPlatform kbWinOS95 kbGrpNet Version : WINDOWS:95,98 Platform : WINDOWS Issue type : kbhowto Last Reviewed: December 7, 1999© 2000 Microsoft Corporation. All rights reserved. Terms of Use. --------------------------------------------------------------------------------Send feedback to MSDN.Look here for MSDN Online resources. 用SendARP()或IP帮助中的一个函数(不好意思,具体是什么俺忘记了,等俺给你查查,晚上再来) 如何得到全部文件路径? 各位帮忙看看这个功能是怎么实现的? 用ado访问oracle,放到了dll里面,程序退出的时候总是崩溃! USB程序编译怎么过不去啊?大家救救,!!!!1 vc6.0使用GDI+的时候 如何保存Graphics类中的图象内容 关于CSocket类的问题: 怎么在窗体上固定的区域内根据输入M行N列的值来产生动态的M*N矩阵的按键??送100分. 如何将EMF格式的图片转化为BMP格式? 关于函数的返回值的问题 拷贝文件时,如何监控进度? ======vc开发数据库,使用存储过程的问题===== 设计时如何确定对话框的精确大小?
ipconfig /all
其中的物理地址不知道是不是你想要的网卡号
NCB ncb;
PUCHAR pData;
ZeroMemory(&ncb, sizeof(ncb));
pData = (PUCHAR)malloc(sizeof(ADAPTER_STATUS) + 16 * sizeof(NAME_BUFFER));
CopyNetbiosName((char *)&ncb.ncb_callname, szName);
ncb.ncb_command = NCBASTAT;
ncb.ncb_buffer = (PUCHAR)pData;
ncb.ncb_lana_num = 0;
ncb.ncb_length = sizeof(ADAPTER_STATUS) + 16 * sizeof(NAME_BUFFER);
Netbios(&ncb);
CString szAddress;
if(ncb.ncb_retcode == NRC_GOODRET)
{
ADAPTER_STATUS *pStatus = (ADAPTER_STATUS *)pData;
UCHAR *pAddress = pStatus->adapter_address;
szAddress.Format("%02X%02X%02X%02X%02X%02X",
pAddress[0], pAddress[1], pAddress[2],
pAddress[3], pAddress[4], pAddress[5]);
bRet = TRUE;
}
else
szAddress = "Wrong Name!";
ID: Q118623 --------------------------------------------------------------------------------
The information in this article applies to:Microsoft Win32 Software Development Kit (SDK), used with:
Microsoft Windows NT, versions 3.1, 3.5, 3.51, 4.0
Microsoft Windows 2000
Microsoft Windows versions 95, 98--------------------------------------------------------------------------------
SUMMARY
This article demonstrates how to get the Media Access Control (MAC) address for an ethernet adapter programmatically by using NetBIOS, if your card is bound to NetBIOS. MORE INFORMATION
To get the Media Access Control (MAC) address for an ethernet adapter programmatically, use the Netbios() NCBASTAT command and provide a "*" as the name in the NCB.ncb_CallName field. This is demonstrated in the sample code below. For computers with multiple network adapters you need to enumerate the LANA numbers and perform the NCBASTAT command on each. Even when you have a single network adapter, it is a good idea to enumerate valid LANA numbers first and perform the NCBASTAT on one of the valid LANA numbers. It is considered bad programming to hardcode the LANA number to 0. In addition, other hardware and software may be assigned their own MAC addresses. For example, a modem can have a MAC address. Also, a RAS client or server can install "dummy" network adapters that correspond to a dialup or serial connection. Normally, these MAC addresses are randomly generated. If an adapter status is called on a LANA that corresponds to one of these adapters when no connection is present, Netbios returns error 0x34 (NRC_ENVNOTDEF) even if a reset was previously performed. With the NetBEUI and IPX transports, the same information can be obtained at a command prompt by using:
net config workstation
The ID given is the MAC address. The following code enumerates all LANA numbers, performs a reset (NCBREST), and an adapter status (NCBASTAT).
Sample Code #include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h> typedef struct _ASTAT_
{ ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30]; }ASTAT, * PASTAT; ASTAT Adapter; void main (void)
{
NCB Ncb;
UCHAR uRetCode;
char NetName[50];
LANA_ENUM lenum;
int i; memset( &Ncb, 0, sizeof(Ncb) );
Ncb.ncb_command = NCBENUM;
Ncb.ncb_buffer = (UCHAR *)&lenum;
Ncb.ncb_length = sizeof(lenum);
uRetCode = Netbios( &Ncb );
printf( "The NCBENUM return code is: 0x%x \n", uRetCode ); for(i=0; i < lenum.length ;i++)
{
memset( &Ncb, 0, sizeof(Ncb) );
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = lenum.lana[i]; uRetCode = Netbios( &Ncb );
printf( "The NCBRESET on LANA %d return code is: 0x%x \n",
lenum.lana[i], uRetCode ); memset( &Ncb, 0, sizeof (Ncb) );
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = lenum.lana[i]; strcpy( Ncb.ncb_callname, "* " );
Ncb.ncb_buffer = (char *) &Adapter;
Ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios( &Ncb );
printf( "The NCBASTAT on LANA %d return code is: 0x%x \n",
lenum.lana[i], uRetCode );
if ( uRetCode == 0 )
{
printf( "The Ethernet Number on LANA %d is:
%02x%02x%02x%02x%02x%02x\n",
lenum.lana[i],
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
} } Additional query words: Keywords : kbnetwork kbAPI kbNetBIOS kbNTOS310 kbNTOS350 kbNTOS351 kbSDKPlatform kbWinOS95 kbGrpNet
Version : WINDOWS:95,98
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: December 7, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.