From c3aea3d947908913707eee4714e5c6deca3705dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Hoerdt?= <mickael.hoerdt@infolibre.ch> Date: Fri, 22 Sep 2023 09:15:50 +0200 Subject: [PATCH] allow to send multiple paquets in one command --- sendether.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) mode change 100644 => 100755 sendether.py diff --git a/sendether.py b/sendether.py old mode 100644 new mode 100755 index 85aaf2d..e5792fc --- a/sendether.py +++ b/sendether.py @@ -4,7 +4,8 @@ import sys import argparse from scapy.all import sendp, sendpfast, Ether, IP, RandIP, RandMAC, ICMP -def macsender(iface): + +def get_etheraddrs(): smac_rand = str(RandMAC('00:*:*:*:*:*')) print(smac_rand) dmac_rand = str(RandMAC('*:*:*:*:*:*')) @@ -12,21 +13,26 @@ def macsender(iface): new = old | 0x1 if old != new: dmac_rand = "{0}{1:x}{2}".format(smac_rand[0], new, smac_rand[2:]) + return smac_rand,dmac_rand + +def macsender(iface,count=1): pkts=[] - pkts.append(Ether(src=smac_rand, dst=str(RandMAC(dmac_rand)))/ - IP(src=str(RandIP('0.0.0.0/0')), dst=str(RandIP('0.0.0.0/0')))/ - ICMP()) + for i in range(count): + ether_src, ether_dst=get_etheraddrs() + pkts.append(Ether(src=ether_src, dst=str(RandMAC(ether_dst)))/ + IP(src=str(RandIP('0.0.0.0/0')), dst=str(RandIP('0.0.0.0/0')))/ + ICMP()) - print(pkts) sendp(pkts, iface=iface, loop=False, verbose=True) def main(): parser = argparse.ArgumentParser(description="Random MAC sender tool") parser.add_argument('-i', '--iface', help="Output interface name") + parser.add_argument('-c', '--count', type=int, default=1, help="Number of packets to send") args = parser.parse_args() try: - macsender(iface = args.iface) + macsender(iface = args.iface, count=args.count) except ValueError as e: print("ERROR: {0}".format(e)) return 1 -- GitLab