Skip to content

Instantly share code, notes, and snippets.

@marcusschiesser
Created November 30, 2021 08:47
Show Gist options
  • Save marcusschiesser/bdb9e90948d267a0a10798e78de10d27 to your computer and use it in GitHub Desktop.
Save marcusschiesser/bdb9e90948d267a0a10798e78de10d27 to your computer and use it in GitHub Desktop.
Test ports for different machines
import socket
machines = ['mickey','mouse']
ports = [8000, 8089, 8088]
# scans ports on the given machines and ports
def scan_ports(machines, ports):
for machine in machines:
for port in ports:
print("Scanning port " + str(port) + " on " + machine)
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.connect((machine, port))
s.close()
print("Port " + str(port) + " is open on " + machine)
except:
print("Port " + str(port) + " is closed on " + machine)
scan_ports(machines, ports)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment