通过arp来得到远程机器的mac地址
2007-07-30 10:45
801 查看
通过arp来得到远程机器的mac地址
include "stdio.h"
#include "stdlib.h"
#include "Winsock2.h"
#include "iphlpapi.h"
#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "Iphlpapi.lib" )
void main( int argc, char ** argv )
{
//处理命令行参数
if ( argc != 2 )
{
printf( "RmtHost v0.1 - Get remote HostName / MacAddress/n" );
printf( "by ShotgunLabs ( Shotgun@xici.net )/n/n" );
printf( "Usage :/n/tRmtHost.exe [RemoteIP]/n/n" );
printf( "Example:/n/tRmtHost.exe 192.168.0.3/n/n" );
exit( 0 );
}
printf( "/nIpAddress : %s/n", argv[1] );
//初始化SOCKET
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
printf( "WSAStartup Error:%d/n", GetLastError() );
exit( 0 );
}
//获取远程机器名
hostent * remoteHostent = (hostent*)malloc( sizeof( hostent ) );
int nRemoteAddr = inet_addr( argv[1] );
remoteHostent = gethostbyaddr( (char*)&nRemoteAddr, sizeof( in_addr ), AF_INET );
if ( remoteHostent )
printf( "HostName : %s/n", remoteHostent->h_name );
else
printf( "gethostbyaddr Error:%d/n", GetLastError() );
//发送ARP查询包获得远程MAC地址
unsigned char macAddress[6];
ULONG macAddLen = 6;
iRet = SendARP( nRemoteAddr, NULL, (PULONG)&macAddress, &macAddLen );
if ( iRet == NO_ERROR )
{
printf( "MacAddress: " );
for( int i =0; i<6; i++ )
{
printf( "%.2x", macAddress[i] );
if ( i<5 ) printf( "-" );
}
}
else
printf( "SendARP Error:%d/n", GetLastError() );
printf( "/n" );
}
include "stdio.h"
#include "stdlib.h"
#include "Winsock2.h"
#include "iphlpapi.h"
#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "Iphlpapi.lib" )
void main( int argc, char ** argv )
{
//处理命令行参数
if ( argc != 2 )
{
printf( "RmtHost v0.1 - Get remote HostName / MacAddress/n" );
printf( "by ShotgunLabs ( Shotgun@xici.net )/n/n" );
printf( "Usage :/n/tRmtHost.exe [RemoteIP]/n/n" );
printf( "Example:/n/tRmtHost.exe 192.168.0.3/n/n" );
exit( 0 );
}
printf( "/nIpAddress : %s/n", argv[1] );
//初始化SOCKET
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
printf( "WSAStartup Error:%d/n", GetLastError() );
exit( 0 );
}
//获取远程机器名
hostent * remoteHostent = (hostent*)malloc( sizeof( hostent ) );
int nRemoteAddr = inet_addr( argv[1] );
remoteHostent = gethostbyaddr( (char*)&nRemoteAddr, sizeof( in_addr ), AF_INET );
if ( remoteHostent )
printf( "HostName : %s/n", remoteHostent->h_name );
else
printf( "gethostbyaddr Error:%d/n", GetLastError() );
//发送ARP查询包获得远程MAC地址
unsigned char macAddress[6];
ULONG macAddLen = 6;
iRet = SendARP( nRemoteAddr, NULL, (PULONG)&macAddress, &macAddLen );
if ( iRet == NO_ERROR )
{
printf( "MacAddress: " );
for( int i =0; i<6; i++ )
{
printf( "%.2x", macAddress[i] );
if ( i<5 ) printf( "-" );
}
}
else
printf( "SendARP Error:%d/n", GetLastError() );
printf( "/n" );
}
相关文章推荐
- 通过 ARP 协议获取局域网内指定 IP 地址的机器的 MAC 地址
- 远程控制篇:通过IP地址得到机器名
- windows机器启动,自动绑定mac 地址[防arp]
- 通过 MAC 地址得到IP的脚本
- C#通过ARP获取指定IP的MAC地址
- C#通过ARP获取指定IP的MAC地址
- 在局域网内中 通过IP地址得到对应的主机名及MAC物理地址
- 通过IP或机器名获取局域网MAC地址
- android判断是否wifi网络连接并得到相应mac地址
- 如何通过HttpURLConnection得到http 302的跳转地址
- C#编程之 如何获取本地和远程主机的IP及MAC地址
- 获取linux机器的IP和mac地址
- 获取机器网卡的物理(MAC)地址
- Mac通过邮件远程遥控电脑自动睡眠
- 使用gethostbyaddr,通过ip地址,得到该ip地址的主机的信息
- mac地址绑定后如何通过路由器实现多台电脑上网
- 如何判断一个C++对象是否在堆栈上(通过VirtualQuery这个API来获取堆栈的起始地址,然后就可以得到答案了),附许多精彩评论
- 获取网卡的MAC地址原码;目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址
- 怎样获取本地机器的MAC地址
- 如何通过HttpURLConnection得到http 302的跳转地址