- 论坛徽章:
- 0
|
获得局域网的机器的MAC地址
//devc++编译,将两个库加载进去
#include
#include
#include
#include
#include
#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "Iphlpapi.lib" )
int main( int argc, char * argv[] )
{
int numberOfHost = 1;
struct hostent *remoteHostent;
//处理命令行参数
if ( argc == 3 )
numberOfHost = atoi( argv[2] );
if ( ( argc >3 ) || ( argc h_name );
else
printf( "gethostbyaddr Error:%d
",GetLastError() );
//发送ARP查询包获得远程MAC地址
unsigned char macAddress[6];
ULONG macAddLen = 6;
iRet=SendARP(nRemoteAddr, (unsigned long)NULL,(PULONG)&macAddress, &macAddLen);
if ( iRet == NO_ERROR )
{
printf( "MacAddress: " );
for( int i =0; i
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/1574/showart_32781.html |
|