北京联想之星投资:谁能帮我这个C++程序调试一下

来源:百度文库 编辑:高考问答 时间:2024/04/30 09:59:50
#include"stdio.h"
#include"stdlib.h"
#include"Winsock2.h"
#include"iphlpapi.h"
typedef DWORD(CALLBACK *PSARP)(
IPAddr DestIP, / /目的主机IP地址
IPAddr SrcIP, / / 源主机IP地址
PULONG pMacAddr, / / 返回的MAC地址
PULONG phyAddrLen / / 返回MAC地址的长度
addr);
);/ /定义结构体
void main(int argc,char **argv[ ])
{
PSARP pSARP;
HINSTANCE hInst; / /实例句柄
hInst =LoadLibrary("iphelpapi.dll"); / /加载IP Helper API所需的库文件
pSARP=(PSARP) GetProcAddress(hInst,"SendARP"); / /获取SendARP函数的地址
/ /处理命令行参数
if(argc!=2)
{
printf("Get a Mac Address from host in a segment!\n");
printf("Usage:\n\GetMac.exe[Host IP]\n\n");
printf("Example:\n\GetMac.exe192.168.0.1\n\n");
exit(0);
}
printf("\nIpAddress:%s\n", argv[1]);
int nRemoteAddr = inet_addr( argv[1]); / /发送ARP查询包获得远程MAC地址
unsigned char macAddress[6];
PULONG macAddLen=6;
int iRet=pSARP(nRemoteAddr,NULL, (PULONG)&macAddress,&macAddLen);
if(iRet==NO_ERROR)
{
printf("MacAddress:");
for(int i=0;i<6;i++) / /格式化输出获取的MAC地址
{
printf ("%.2x",macAddress[i]);
if(i<5)
printf("-");
}
}
else
printf("SendARP Error:%d\n",GetLastError( ));
printf("\n");
}