获取MAC地址:#include "stdafx.h"
#include "mac.h"//using namespace std;bool GetAdapterInfo(int nAdapterNum, char sMAC[C_MAC_LEN])
{
// Reset the LAN adapter so that we can begin querying it
NCB Ncb;
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = nAdapterNum;
if (Netbios(&Ncb) != NRC_GOODRET)
{
_snprintf(sMAC,C_MAC_LEN,"r:0x%02X",Ncb.ncb_retcode);
return false;
}
// Prepare to get the adapter status block
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = nAdapterNum;
strcpy((char *) Ncb.ncb_callname, "*");
struct ASTAT {
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff[30];
} Adapter;
memset(&Adapter, 0, sizeof(Adapter));
Ncb.ncb_buffer = (unsigned char *)&Adapter;
Ncb.ncb_length = sizeof(Adapter);
// Get the adapter's info and, if this works, return it in standard,
// colon-delimited form.
if (Netbios(&Ncb) == 0) {
char acMAC[18];
sprintf(acMAC, "%02X:%02X:%02X:%02X:%02X:%02X",
int (Adapter.adapt.adapter_address[0]),
int (Adapter.adapt.adapter_address[1]),
int (Adapter.adapt.adapter_address[2]),
int (Adapter.adapt.adapter_address[3]),
int (Adapter.adapt.adapter_address[4]),
int (Adapter.adapt.adapter_address[5]));
memcpy(sMAC,acMAC,C_MAC_LEN);
sMAC[C_MAC_LEN] = 0;
return true;
}
else {
_snprintf(sMAC,C_MAC_LEN,"a:0x%02X",Ncb.ncb_retcode);
return false;
}
}
#include "mac.h"//using namespace std;bool GetAdapterInfo(int nAdapterNum, char sMAC[C_MAC_LEN])
{
// Reset the LAN adapter so that we can begin querying it
NCB Ncb;
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = nAdapterNum;
if (Netbios(&Ncb) != NRC_GOODRET)
{
_snprintf(sMAC,C_MAC_LEN,"r:0x%02X",Ncb.ncb_retcode);
return false;
}
// Prepare to get the adapter status block
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = nAdapterNum;
strcpy((char *) Ncb.ncb_callname, "*");
struct ASTAT {
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff[30];
} Adapter;
memset(&Adapter, 0, sizeof(Adapter));
Ncb.ncb_buffer = (unsigned char *)&Adapter;
Ncb.ncb_length = sizeof(Adapter);
// Get the adapter's info and, if this works, return it in standard,
// colon-delimited form.
if (Netbios(&Ncb) == 0) {
char acMAC[18];
sprintf(acMAC, "%02X:%02X:%02X:%02X:%02X:%02X",
int (Adapter.adapt.adapter_address[0]),
int (Adapter.adapt.adapter_address[1]),
int (Adapter.adapt.adapter_address[2]),
int (Adapter.adapt.adapter_address[3]),
int (Adapter.adapt.adapter_address[4]),
int (Adapter.adapt.adapter_address[5]));
memcpy(sMAC,acMAC,C_MAC_LEN);
sMAC[C_MAC_LEN] = 0;
return true;
}
else {
_snprintf(sMAC,C_MAC_LEN,"a:0x%02X",Ncb.ncb_retcode);
return false;
}
}
解决方案 »
- flex绘制拓扑图的问题
- 欢迎Java方面的高手来给小弟撑门!!!!!
- ibatis中nullValue设置不起作用
- 关于找工作,进来看看
- 100分请教:不用MyEclipse等辅助工具,在Eclipse环境下,怎样配置使Hibernate能运行?
- Jboss中配多个域名对多个目录
- 我的deploytool怎么了?
- EJB问题: CMP的home接口中可否自己定义一些方法, 完成一些cmp不能做的事情,如MaxXxx().
- struts2 中namespace的问题
- 使用纯html能获取到session的值么,怎么获取,求大神,最好能给点样式代码
- 请问有什么工具可以自动生成数据表和JAVA类 的对应关系
- jsp在tomcat运行的问题
#include "stdafx.h"
#include "volserial.h"BOOL GetVolumeSerialNumber (LPCSTR pszRootPathName, DWORD *pdwSerialNum)
{
BOOL bReturn = FALSE; // Assume that we haven't get the serial number,
// then set it to true if we do get it. HANDLE hFile;
BY_HANDLE_FILE_INFORMATION bhFileInfo; HANDLE hFileFind;
WIN32_FIND_DATA wfdFileData;
char szFindFileName[MAX_PATH];
/*
Search for any file that we can open and retrieve information about.
That information will include the serial number of the volume on
which the file resides.
*/
lstrcpy (szFindFileName, pszRootPathName);
lstrcat (szFindFileName, "*"); hFileFind = FindFirstFile (szFindFileName, &wfdFileData);
if (INVALID_HANDLE_VALUE == hFileFind)
goto EXIT_DONE; do
{
/* Make sure that we've found a file and not a directory */
if (!(wfdFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
/*
Found a file. Now, use the full path to open the file and get
information about it. This information includes the serial
number of the volume on which the file resides. If we do get
the info, we can bail out because we're done. If we can't open this file, look for another one we can open.
*/
lstrcpy (szFindFileName+lstrlen(pszRootPathName),
wfdFileData.cFileName); hFile = CreateFile (szFindFileName,
0, // don't need to open for read or write
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE != hFile)
{
bReturn = GetFileInformationByHandle(hFile, &bhFileInfo);
CloseHandle(hFile); if (bReturn)
break;
}
}
}
while (FindNextFile(hFileFind, &wfdFileData));
CloseHandle (hFileFind); /* don't need the find handle anymore */ /* If we have the serial number, return it to the caller */
if (bReturn )
{
__try
{
*pdwSerialNum = bhFileInfo.dwVolumeSerialNumber;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
SetLastError (ERROR_INVALID_PARAMETER);
bReturn = FALSE;
}
}EXIT_DONE:
return (bReturn);
}