Skip to content

Instantly share code, notes, and snippets.

@ImanMousavi
Created February 16, 2020 12:45
Show Gist options
  • Save ImanMousavi/a22371e830352eb5ff9cc38ea71bf104 to your computer and use it in GitHub Desktop.
Save ImanMousavi/a22371e830352eb5ff9cc38ea71bf104 to your computer and use it in GitHub Desktop.
check network port in python
# test if an [ip:port] is open
import socket
def isOpen(ip,port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((ip, int(port)))
s.shutdown(2)
return True
except:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment