Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import os
- def send_image(image_path, ip):
- """Send image bytes to a specific IP address."""
- # Create a UDP socket
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- # Read the image file in binary mode
- with open(image_path, 'rb') as file:
- image_data = file.read()
- try:
- # Send the image data
- sock.sendto(image_data, (ip, 12345)) # Use a port of your choice
- print(f"Sent image to {ip}")
- except Exception as e:
- print(f"Failed to send image to {ip}: {e}")
- finally:
- sock.close()
- def ping_image(image_path, ip_range):
- """Ping specified IPs with the given image."""
- # Split the IP range into start and end
- start_ip, end_ip = ip_range.split('-')
- # Convert the start and end IPs to integers for iteration
- start = list(map(int, start_ip.split('.')))
- end = list(map(int, end_ip.split('.')))
- for i in range(start[2], end[2] + 1): # Modify based on subnet
- for j in range(start[3], end[3] + 1):
- ip = f"{start[0]}.{start[1]}.{start[2]}.{j}"
- send_image(image_path, ip)
- def main():
- """Main function to execute commands."""
- while True:
- command = input("Enter command: ")
- if command.startswith('/ping'):
- try:
- _, image_file, ip_range = command.split()
- if not os.path.isfile(image_file):
- print("Image file does not exist.")
- continue
- ping_image(image_file, ip_range)
- except ValueError:
- print("Invalid command format. Use: /ping image.filetype ip-ip")
- elif command.lower() == 'exit':
- print("Exiting the program.")
- break
- else:
- print("Unknown command. Type '/ping image.filetype ip-ip'.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement