Created
February 3, 2011 10:59
-
-
Save sente/809347 to your computer and use it in GitHub Desktop.
scan for open ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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