need to scan dem ips for the cuppers…some gay ass verbose outputs during the scan and then outputting GOOD servers file.
Python
import socket
import ipaddress
# Define colors for console output
RED = '\033[91m'
GREEN = '\033[92m'
RESET = '\033[0m'
good_servers = [] # To store good servers for logging
def check_cups_server(ip):
port = 631
try:
# Create a socket with a 0.25-second timeout
sock = socket.create_connection((ip, port), timeout=0.25)
# Construct a simple IPP request (Get Printer Attributes)
request = b'\x01\x01\x00\x01\x00\x00\x00\x00' # Sample IPP request
sock.sendall(request)
# Receive response
response = sock.recv(4096)
sock.close()
# Check if the response indicates a valid CUPS server
if response:
return True
except (socket.timeout, ConnectionRefusedError, OSError):
return False
return False
def scan_network(network):
for ip in network.hosts(): # Iterate over all usable hosts in the network
print(f"Scanning {ip}...", end="\r") # Show current IP being scanned
if check_cups_server(str(ip)):
good_output = f"{GREEN}GOOD: {ip}{RESET}"
print(good_output)
good_servers.append(str(ip)) # Add to good servers list
else:
bad_output = f"{RED}BAD: {ip}{RESET}"
print(bad_output)
def main():
network_input = input("Enter the network (e.g., 195.95.233.0/24): ")
try:
# Create an IPv4 network object
network = ipaddress.ip_network(network_input, strict=False)
# If the network is a /32, just check that single IP
if network.prefixlen == 32:
print(f"Scanning {network.network_address}...")
if check_cups_server(str(network.network_address)):
print(f"{GREEN}GOOD: {network.network_address}{RESET}")
good_servers.append(str(network.network_address))
else:
print(f"{RED}BAD: {network.network_address}{RESET}")
else:
scan_network(network)
# Log good servers to a file
if good_servers: # Only log if there are good servers
with open("good_cups_servers.txt", "w") as log_file:
for server in good_servers:
log_file.write(server + "\n")
print(f"\nGood CUPS servers logged to 'good_cups_servers.txt'.")
else:
print("\nNo good CUPS servers found.")
except ValueError as e:
print(f"Invalid network input: {e}")
if __name__ == "__main__":
main()