Skip to content

Instantly share code, notes, and snippets.

@sht
Last active April 15, 2021 21:33
Show Gist options
  • Save sht/2a3e9cdf73c5695daed8d309577eb05d to your computer and use it in GitHub Desktop.
Save sht/2a3e9cdf73c5695daed8d309577eb05d to your computer and use it in GitHub Desktop.
to check the status of port on particular IP
# I don't trust nmap all the time. Alternatively, we can either use telnet for single IP or below mentioned script for multiple IPs
import socket
def checkIpPort(ip,port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
status = s.connect_ex((ip, port))
if status == 0:
print(f"Is port {port} open on {ip}?: Yes")
else:
print(f"Is port {port} open on {ip}?: No")
s.close()
return status
ips = ['10.128.1.10','3.125.252.47'] # List of ips
for ip in ips:
checkIpPort(ip,22)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment