Skip to content

Instantly share code, notes, and snippets.

@jermenkoo
Created December 21, 2012 23:36
Show Gist options
  • Save jermenkoo/4356589 to your computer and use it in GitHub Desktop.
Save jermenkoo/4356589 to your computer and use it in GitHub Desktop.
import socket
socket.setdefaulttimeout(0.2)
def isOpen(ip, port):
ip = socket.gethostbyname(ip)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if s.connect_ex((ip, int(port))) == 0:
return True
else:
return False
s.close()
print(isOpen("www.google.com", 80))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment