Skip to content

Instantly share code, notes, and snippets.

@sente
Created February 3, 2011 10:59
Show Gist options
  • Save sente/809347 to your computer and use it in GitHub Desktop.
Save sente/809347 to your computer and use it in GitHub Desktop.
scan for open ports
from twisted.internet import reactor, defer
from connectiontester import testConnect
def handleAllResults(allResults, ports):
for port, results in zip(ports, allResults):
success, result = results
if success:
print "Connected to port %i" % port
reactor.stop()
import sys
host = sys.argv[1]
ports = range(1, 201)
testers = [testConnect(host, port) for port in ports]
defer.DeferredList(testers, consumeErrors=True).addCallback(
handleAllResults, ports)
reactor.run()
# $ python portscan.py localhost
#Connected to port 21
#Connected to port 22
#Connected to port 25
#Connected to port 80
#Connected to port 81
#Connected to port 111
#Connected to port 139
#Connected to port 143
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment