arp.c
来源:互联网 发布:手机互传有哪些软件 编辑:程序博客网 时间:2024/06/05 05:28
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <pcap.h>
void delay(void) /*延时函数*/
{
int m,n,s;
for(m=150;m>0;m--)
for(n=200;n>0;n--)
for(s=240;s>0;s--);
}
void main(int argc, char **argv)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
u_char packet[100];
int j;
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
exit(1);
}
/* 打印列表 */
for(d=alldevs; d; d=d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf(" (%s)\n", d->description);
else
printf(" (No description available)\n");
}
if(i==0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return -1;
}
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(alldevs);
return -1;
}
/* 跳转到选中的适配器 */
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
/* 打开输出设备 */
if ( (fp= pcap_open(d=d->name, // 设备名
100, // 要捕获的部分 (只捕获前100个字节)
PCAP_OPENFLAG_PROMISCUOUS, // 混杂模式
1000, // 读超时时间
NULL, // 远程机器验证
errbuf // 错误缓冲
) ) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", argv[1]);
return;
}
/* 目的地址的MAC地址*/
packet[0]=0xff;
packet[1]=0xff;
packet[2]=0xff;
packet[3]=0xff;
packet[4]=0xff;
packet[5]=0xff;
/* 设置MAC源地址 */
packet[6]=0x00;
packet[7]=0x1e;
packet[8]=0xec;
packet[10]=0x9e;
packet[9]=0x65;
packet[11]=0x19;
/* 帧类型 */
packet[12]=0x08;
packet[13]=0x06;
/* 硬件类型 */
packet[14]=0x00;
packet[15]=0x01;
/* 协议类型 */
packet[16]=0x08;
packet[17]=0x00;
/* op */
packet[18]=0x06;
packet[19]=0x04;
/* ARP回复协议 */
packet[20]=0x00;
packet[21]=0x02;
for(i=22;i<28;i++)
packet[i]=packet[i-16];
packet[28]=0xc0;
packet[29]=0xa8;
packet[30]=0x01;
packet[31]=0x67;
packet[32]=0x00;
packet[33]=0x19;
packet[34]=0xe0;
packet[35]=0xbf;
packet[36]=0xbd;
packet[37]=0x3e;
packet[38]=0xc0;
packet[39]=0xa8;
packet[40]=0x01;
packet[41]=0x01;
for(j=42;j<60;j++)
{
packet[j]=0x00;
}
while(1)
{
pcap_sendpacket(fp, packet, 60 /* size */);
delay();
}
/* 发送数据包 */
if(pcap_sendpacket(fp, packet, 60 /* size */) != 0)
{
fprintf(stderr,"\nError sending the packet: \n", pcap_geterr(fp));
// return;
}
return;
}
#include <stdio.h>
#include <dos.h>
#include <pcap.h>
void delay(void) /*延时函数*/
{
int m,n,s;
for(m=150;m>0;m--)
for(n=200;n>0;n--)
for(s=240;s>0;s--);
}
void main(int argc, char **argv)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
u_char packet[100];
int j;
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
exit(1);
}
/* 打印列表 */
for(d=alldevs; d; d=d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf(" (%s)\n", d->description);
else
printf(" (No description available)\n");
}
if(i==0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return -1;
}
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(alldevs);
return -1;
}
/* 跳转到选中的适配器 */
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
/* 打开输出设备 */
if ( (fp= pcap_open(d=d->name, // 设备名
100, // 要捕获的部分 (只捕获前100个字节)
PCAP_OPENFLAG_PROMISCUOUS, // 混杂模式
1000, // 读超时时间
NULL, // 远程机器验证
errbuf // 错误缓冲
) ) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", argv[1]);
return;
}
/* 目的地址的MAC地址*/
packet[0]=0xff;
packet[1]=0xff;
packet[2]=0xff;
packet[3]=0xff;
packet[4]=0xff;
packet[5]=0xff;
/* 设置MAC源地址 */
packet[6]=0x00;
packet[7]=0x1e;
packet[8]=0xec;
packet[10]=0x9e;
packet[9]=0x65;
packet[11]=0x19;
/* 帧类型 */
packet[12]=0x08;
packet[13]=0x06;
/* 硬件类型 */
packet[14]=0x00;
packet[15]=0x01;
/* 协议类型 */
packet[16]=0x08;
packet[17]=0x00;
/* op */
packet[18]=0x06;
packet[19]=0x04;
/* ARP回复协议 */
packet[20]=0x00;
packet[21]=0x02;
for(i=22;i<28;i++)
packet[i]=packet[i-16];
packet[28]=0xc0;
packet[29]=0xa8;
packet[30]=0x01;
packet[31]=0x67;
packet[32]=0x00;
packet[33]=0x19;
packet[34]=0xe0;
packet[35]=0xbf;
packet[36]=0xbd;
packet[37]=0x3e;
packet[38]=0xc0;
packet[39]=0xa8;
packet[40]=0x01;
packet[41]=0x01;
for(j=42;j<60;j++)
{
packet[j]=0x00;
}
while(1)
{
pcap_sendpacket(fp, packet, 60 /* size */);
delay();
}
/* 发送数据包 */
if(pcap_sendpacket(fp, packet, 60 /* size */) != 0)
{
fprintf(stderr,"\nError sending the packet: \n", pcap_geterr(fp));
// return;
}
return;
}
- arp.c
- ARP C代码实现
- ARP--C语言Windows实现
- ARP的C代码实现
- Linux-ARP请求C程序
- ARP
- ARP
- ARP
- ARP
- ARP
- ARP
- ARP
- arp
- arp
- ARP
- ARP
- ARP
- ARP
- 好像不错
- POJ 1279 Art Gallery(半平面交)
- java.sql.SQLException:ORA-00923:未找到要求的From
- C语言实现模拟键盘按键事件
- css
- arp.c
- C++中的volatile关键字
- 解决ubuntu12.04耳机有声音,外放没声音的问题
- Swing菜单
- sniffer.c
- java.sql.SQLException:Ref 游标无效
- Linux进程间通信类型
- java使窗口全屏
- p '这也会显示双引号' print "这不会显示双引号"