#!/usr/bin/env python
import argparse
import sys
from scapy.all import *
def get_alphabets(count: int) -> str:
alphabets = list(range(97, 123))
alphabets.extend(list(range(65, 91)))
return get_characters(alphabets, count)
def get_characters(alphabets: list, count: int) -> str:
result = ''
index = 0
for i in range(0, count):
result += chr(alphabets[index])
index += 1
if len(alphabets) <= index:
index = 0
return result
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--fragmentsize', default=500,
type=int, help="Fragment size")
parser.add_argument('-i', '--id', default=12345, type=int, help="ID")
parser.add_argument('-l', '--length', default=1500,
type=int, help="Packet length")
parser.add_argument('-s', '--sport', default=10001,
type=int, help="Source port")
parser.add_argument('-d', '--dport', default=10002,
type=int, help="Destination port")
parser.add_argument('-p', '--protocol', default="udp",
type=str, help="Protocol")
parser.add_argument('address', type=str, help="Destination address")
args = parser.parse_args()
payload = get_alphabets(args.length)
if args.protocol.lower() == "icmp":
packet = IP(dst=args.address, id=args.id) / \
ICMP()/payload
elif args.protocol.lower() == "udp":
packet = IP(dst=args.address, id=args.id) / \
UDP(sport=args.sport, dport=args.dport)/payload
elif args.protocol.lower() == "tcp":
packet = IP(dst=args.address, id=args.id) / \
TCP(sport=args.sport, dport=args.dport)/payload
else:
sys.exit(-1)
frags = fragment(packet, fragsize=args.fragmentsize)
count = 1
for fragment in frags:
count += 1
send(fragment, verbose=False)
print("Sent " + str(count) + " " + args.protocol.lower() + " packet(s).")