首页 电脑 电脑学堂 查看内容

得到远程机器MAC地址源代码

2004-9-29 20:05 611 0

摘要: 网上收集 如侵犯您的权力,对请来信告知#include #include #include #include "iphlpapi.h"#pragma comment ( lib, "ws2_32.li...
关键词: printf nRemoteAddr remoteHostent MacAddress include GetLastError struct int Error tRmtHost

网上收集 如侵犯您的权力,对请来信告知#include #include #include #include "iphlpapi.h"#pragma comment ( lib, "ws2_32.lib" )#pragma comment ( lib, "Iphlpapi.lib" )void main( int argc, char ** argv ){int numberOfHost = 1;struct hostent *remoteHostent;//处理命令行参数if ( argc == 3 )numberOfHost = atoi( argv[2] );if ( ( argc >3 ) || ( argc {printf( "RmtHost v0.2 - Get remote HostName /MacAddress\n" );printf( "by ShotgunLabs ( [email protected] )\n\n" );printf( "Usage :\n\tRmtHost.exe [RemoteIP]\n\n" );printf( "Example:\n\tRmtHost.exe 192.168.0.3\n" );printf( "\tRmtHost.exe 192.168.0.3 255\n\n" );exit( 0 );}//初始化SOCKETWSADATA wsaData;int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);if ( iRet != 0 ){printf( "WSAStartup Error:%d\n", GetLastError() );exit( 0 );}int nRemoteAddr = inet_addr( argv[1] );remoteHostent= (struct hostent*)malloc( sizeof(struct hostent ));struct in_addr sa;for ( int i = 0; i {//获取远程机器名sa.s_addr = nRemoteAddr;printf( "\nIpAddress : %s\n", inet_ntoa( sa ) );remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET );if ( remoteHostent )printf( "HostName : %s\n",remoteHostent->h_name );elseprintf( "gethostbyaddr Error:%d\n",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{printf( "%.2x", macAddress[i] );if ( i}printf( "\n" );}elseprintf( "SendARP Error:%d\n", GetLastError());nRemoteAddr = htonl( ntohl( nRemoteAddr ) + 1 );}}
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部