Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import platform
- import socket
- import subprocess
- import threading
- import time
- # Set a port number for sending/receiving data (UDP)
- PORT = 8080
- BUFFER_SIZE = 1024 # Maximum size of data to be received
- known_ips = [] # List to store known IPs
- def get_local_ip():
- """Get the local IP address of the machine."""
- hostname = socket.gethostname()
- local_ip = socket.gethostbyname(hostname)
- return local_ip
- def get_network_prefix():
- """Get the network prefix and subnet mask."""
- local_ip = get_local_ip()
- # Automatically determine subnet (default to /24)
- return '.'.join(local_ip.split('.')[:-1])
- def ping_sweep():
- """Perform a ping sweep across all IPs in the local network."""
- network_prefix = get_network_prefix()
- param = '-n' if platform.system().lower() == 'windows' else '-c'
- active_ips = []
- for i in range(1, 255):
- ip = f"{network_prefix}.{i}"
- command = ['ping', param, '1', ip]
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- if result.returncode == 0:
- active_ips.append(ip)
- return active_ips
- def ping_specific_ip(ip_address):
- """Ping a specific local IP address."""
- param = '-n' if platform.system().lower() == 'windows' else '-c'
- command = ['ping', param, '1', ip_address]
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- return result.returncode == 0 # Return True if the ping is successful
- def beep_alert():
- """Make a 1000 Hz beep for 1 second (on Windows) or a system beep for Unix."""
- if platform.system().lower() == 'windows':
- import winsound
- winsound.Beep(1000, 1000) # 1000 Hz for 1 second
- else:
- os.system('echo -e "\\a"')
- def antihack():
- """Run the antihack system to monitor for unknown IPs."""
- while True:
- active_ips = ping_sweep()
- for ip in active_ips:
- if ip not in known_ips:
- print(f"Unknown IP: {ip}!")
- beep_alert() # Trigger the alert
- time.sleep(5) # Wait for 5 seconds before the next sweep
- def send_data_to_ip(data, ip_address):
- """Send the data to a specific IP address using UDP."""
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- try:
- sock.sendto(data.encode(), (ip_address, PORT))
- print(f"Data sent to {ip_address}: {data}")
- except Exception as e:
- print(f"Failed to send data to {ip_address}: {e}")
- finally:
- sock.close()
- def receive_data_from_ip(ip_address=None):
- """Receive data from a specific IP address or listen to all."""
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- try:
- sock.bind((ip_address if ip_address else '', PORT))
- print(f"Listening for data on IP {ip_address if ip_address else 'all local IPs'}...")
- while True:
- data, addr = sock.recvfrom(BUFFER_SIZE)
- print(f"Received data from {addr}: {data.decode()}")
- except Exception as e:
- print(f"Failed to receive data: {e}")
- finally:
- sock.close()
- def handle_command(command):
- """Handle commands entered by the user."""
- if command == '/ping local all':
- active_ips = ping_sweep()
- print(f"Active IPs: {', '.join(active_ips)}")
- elif command.startswith('/ping local'):
- parts = command.split()
- if len(parts) == 3:
- ip_address = parts[2]
- if ping_specific_ip(ip_address):
- print(f"Ping to {ip_address} was successful!")
- else:
- print(f"Ping to {ip_address} failed.")
- else:
- print("Usage: /ping local x.x.x.x")
- elif command.startswith('/ping global'):
- parts = command.split()
- if len(parts) == 3:
- ip_address = parts[2]
- if ping_specific_ip(ip_address):
- print(f"Ping to {ip_address} was successful!")
- else:
- print(f"Ping to {ip_address} failed.")
- else:
- print("Usage: /ping global x.x.x.x")
- elif command.startswith('/datasend local all'):
- data = command.split('"')[1] # Extract the data inside quotes
- send_data_to_all_local(data)
- elif command.startswith('/datasend local'):
- parts = command.split()
- if len(parts) == 4:
- data = parts[1].strip('"')
- ip_address = parts[3]
- send_data_to_ip(data, ip_address)
- else:
- print('Usage: /datasend local "data" x.x.x.x')
- elif command.startswith('/datasend global'):
- parts = command.split()
- if len(parts) == 4:
- data = parts[1].strip('"')
- ip_address = parts[3]
- send_data_to_ip(data, ip_address)
- else:
- print('Usage: /datasend global "data" x.x.x.x')
- elif command == '/datareceive local all':
- threading.Thread(target=receive_data_from_ip).start()
- elif command.startswith('/datareceive local'):
- parts = command.split()
- if len(parts) == 3:
- ip_address = parts[2]
- threading.Thread(target=receive_data_from_ip, args=(ip_address,)).start()
- else:
- print("Usage: /datareceive local x.x.x.x")
- elif command.startswith('/datareceive global'):
- parts = command.split()
- if len(parts) == 3:
- ip_address = parts[2]
- threading.Thread(target=receive_data_from_ip, args=(ip_address,)).start()
- else:
- print("Usage: /datareceive global x.x.x.x")
- elif command.startswith('/ahlist add'):
- parts = command.split()
- if len(parts) == 3:
- ip_address = parts[2]
- if ip_address not in known_ips:
- known_ips.append(ip_address)
- print(f"Added {ip_address} to known IP list.")
- else:
- print(f"{ip_address} is already in the known IP list.")
- else:
- print("Usage: /ahlist add x.x.x.x")
- elif command == '/antihack':
- print("Starting antihack monitoring...")
- threading.Thread(target=antihack).start()
- else:
- print("Unknown command. Try '/ping local all', '/ping local x.x.x.x', '/ping global x.x.x.x', '/datasend local', '/datasend global', '/datareceive local', '/datareceive global', '/ahlist add', or '/antihack'.")
- if __name__ == "__main__":
- while True:
- # Get user input
- user_input = input("Enter command: ").strip()
- # Handle exit command
- if user_input.lower() in ['exit', 'quit']:
- print("Exiting program.")
- break
- # Handle the command
- handle_command(user_input)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement