C/C++ code#include
#include
#include
#include
#include
#include
#include
#include
#include
char *ip = "192.168.205.168";
int main()
{
struct arpreq arp;
/**/
struct sockaddr_in * paddr = (struct sockaddr_in *)&arp.arp_pa;;
int s, ret = 0;
char *mac = arp.arp_pa.sa_data;
s = socket(AF_INET, SOCK_STREAM, 0);
paddr->sin_family = AF_INET;
paddr->sin_port = htons(9090);
paddr->sin_addr.s_addr = inet_addr(ip);
strcpy(arp.arp_dev, "eth0");
ret = ioctl(s, SIOCGARP, &arp);
if(ret == -1)
{
perror("ioctl SIOCGARP");
exit(1);
}
printf("%2x-%2x-%2x-%2x-%2x-%2x\n",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
return 0;
}