-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtornado.py
More file actions
30 lines (25 loc) · 897 Bytes
/
tornado.py
File metadata and controls
30 lines (25 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import tornado.ioloop
import tornado.web
import socket
class PortScanHandler(tornado.web.RequestHandler):
def get(self):
hostname = self.get_argument('hostname')
start_port = int(self.get_argument('start_port'))
end_port = int(self.get_argument('end_port'))
open_ports = []
for port in range(start_port, end_port+1):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((hostname, port))
if result == 0:
open_ports.append(port)
sock.close()
self.write('Open ports: ' + str(open_ports))
def make_app():
return tornado.web.Application([
(r"/portscan", PortScanHandler),
])
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()