This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
netsec-djw2/final/scripts/ttl.py
2024-06-13 02:19:58 -07:00

34 lines
968 B
Python

import sys
from scapy.all import sniff, send, IP, IPv6
from datetime import datetime
modifications = 0
def modify_packet(packet):
if packet.haslayer(IP):
if packet[IP].ttl != 65:
packet[IP].ttl = 65
modifications += 1
elif packet.haslayer(IPv6):
if packet[IPv6].ttl != 65:
packet[IPv6].ttl = 65
modifications += 1
#Can be extented with other protocols which have TTL
send(packet)
if __name__ == "__main__":
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <interface>")
sys.exit(1)
interface = sys.argv[1]
start_time = datetime.now()
print(f"Script started at: {start_time.strftime('%Y-%m-%d %H:%M:%S')}")
packets = sniff(filter="ip or ipv6", iface=interface, timeout=30*1, prn=modify_packet)
end_time = datetime.now()
print(f"Script ended at: {end_time.strftime('%Y-%m-%d %H:%M:%S')}")
print(f"{modifications} packets modified")