|
| 1 | +# Import the neccasary modules. |
| 2 | +importsys |
| 3 | +fromscapy.allimportsr,IP,ICMP |
| 4 | +fromfakerimportFaker |
| 5 | +fromcoloramaimportFore,init |
| 6 | + |
| 7 | +# Initialize colorama for colored console output. |
| 8 | +init() |
| 9 | +# Create a Faker object for generating fake data. |
| 10 | +fake=Faker() |
| 11 | + |
| 12 | +# Function to generate a fake IPv4 address. |
| 13 | +defgenerate_fake_ip(): |
| 14 | +returnfake.ipv4() |
| 15 | + |
| 16 | +# Function to craft and send an ICMP packet. |
| 17 | +defcraft_and_send_packet(source_ip,destination_ip): |
| 18 | +# Craft an ICMP packet with the specified source and destination IP. |
| 19 | +packet=IP(src=source_ip,dst=destination_ip)/ICMP() |
| 20 | +# Send and receive the packet with a timeout. |
| 21 | +answers,_=sr(packet,verbose=0,timeout=5) |
| 22 | +returnanswers |
| 23 | + |
| 24 | +# Function to display a summary of the sent and received packets. |
| 25 | +defdisplay_packet_summary(sent,received): |
| 26 | +print(f"{Fore.GREEN}[+] Sent Packet:{sent.summary()}\n") |
| 27 | +print(f"{Fore.MAGENTA}[+] Response:{received.summary()}") |
| 28 | + |
| 29 | +# Check if the correct number of command-line arguments is provided. |
| 30 | +iflen(sys.argv)!=2: |
| 31 | +print(f"{Fore.RED}[-] Error!{Fore.GREEN} Please run as:{sys.argv[0]} <dst_ip>") |
| 32 | +sys.exit(1) |
| 33 | + |
| 34 | +# Retrieve the destination IP from the command-line arguments. |
| 35 | +destination_ip=sys.argv[1] |
| 36 | +# Generate a fake source IP. |
| 37 | +source_ip=generate_fake_ip() |
| 38 | +# Craft and send the packet, and receive the response. |
| 39 | +answers=craft_and_send_packet(source_ip,destination_ip) |
| 40 | +# Display the packet summary for each sent and received pair. |
| 41 | +forsent,receivedinanswers: |
| 42 | +display_packet_summary(sent,received) |