//
// Link with ws2_32.lib and iphlpapi.lib
//
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "iphlpapi.h"
#pragma comment(lib,"Iphlpapi.lib")
#pragma comment(lib,"Ws2_32.lib")
int __cdecl main(int argc,char *argv[])
{
FILE *stream;
char c = '\n';
HRESULT hr;
IPAddr ipAddr;
ULONG pulMac[2];
ULONG ulLen;
if (argc!=2)
{
//printf("USAGE:\t%s Start_IP End_IP\n",argv[0]);
return 1;
}
ipAddr = inet_addr (argv[1]);
memset (pulMac, 0xff, sizeof (pulMac));
ulLen = 6;
hr = SendARP (ipAddr, 0, pulMac, &ulLen);
if (hr==NO_ERROR)
{
stream=fopen("host.txt","a");
fprintf(stream,"%s%c", argv[1], c);
fclose( stream );
size_t i, j;
char * szMac = new char[ulLen*3];
PBYTE pbHexMac = (PBYTE) pulMac;
//
// Convert the binary MAC address into human-readable
//
for (i = 0, j = 0; i < ulLen - 1; ++i) {
j += sprintf (szMac + j, "%02X:", pbHexMac[i]);
}
printf ("%-15s",argv[1]);
sprintf (szMac + j, "%02X", pbHexMac[i]);
printf (" MAC address %s\n", szMac);
delete [] szMac;
}
return 0;
}
评论5
最新资源