Created
November 29, 2015 21:03
-
-
Save nicolargo/d220f67da6d826cc9137 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import asyncore | |
import socket | |
class PortScanner(asyncore.dispatcher): | |
def __init__(self, host, port): | |
self.host = host | |
self.port = port | |
asyncore.dispatcher.__init__(self) | |
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
self.connect((host, port)) | |
except Exception as e: | |
print 'Connection error for %s:%s (%s)' % (self.host, self.port, e) | |
self.close() | |
def handle_connect(self): | |
print 'Connected to %s:%s' % (self.host, self.port) | |
self.close() | |
scanlist = [] | |
scanlist.append(PortScanner('www.google.fr', 443)) | |
scanlist.append(PortScanner('www.inria.fr', 80)) | |
scanlist.append(PortScanner('www.inria.fr', 1024)) | |
scanlist.append(PortScanner('www.nonXXXexistingXXX.com', 80)) | |
asyncore.loop(timeout=1, count=3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: use AsyncIO: http://makina-corpus.com/blog/metier/2015/python-http-server-with-the-new-async-await-syntax