Skip to content

Instantly share code, notes, and snippets.

@vanne02135
Created May 21, 2010 12:54
Show Gist options
  • Save vanne02135/408791 to your computer and use it in GitHub Desktop.
Save vanne02135/408791 to your computer and use it in GitHub Desktop.
Test for open ports
import socket
import sys
host = sys.argv[1]
maxport = int(sys.argv[2])
for k in range(1, maxport):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.5)
s.connect((host, k))
#c = socket.connect((host, k), 1)
print "%s : %d responds" % (host, k)
s.close()
except:
pass
#print "no response in %s : %d" % (host, k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment