Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created May 27, 2009 22:50
Show Gist options
  • Save seungjin/118965 to your computer and use it in GitHub Desktop.
Save seungjin/118965 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# connectionCheck
import sys
from urllib2 import urlopen
import socket
host = sys.argv[1]
port = int(sys.argv[2])
size = 1024
s = None
try:
socket.setdefaulttimeout(1)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
except socket.timeout, (message):
if s:
s.close()
print "Socket opened but connection timeout"
sys.exit(1)
except socket.error, (value,message):
if s:
s.close()
print "Could not open socket: " + message
sys.exit(1)
#s.send('Hello, world')
#data = s.recv(size)
s.close()
#print 'Received:', data
print "Connection Ok! "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment