Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from socket import socket
- from select import select
- tmout = 1
- chunk = 300
- def scan_chunk(host, begin_port, end_port):
- socks = []
- for port in range(begin_port, end_port):
- sock = socket()
- sock.setblocking(False)
- try:
- sock.connect((host, port))
- except BlockingIOError:
- pass
- socks.append(sock)
- r, w, x = select([], socks, [], tmout)
- for sock in w:
- port = sock.getpeername()[1]
- print(port, 'connected')
- for sock in socks:
- sock.close()
- host = input('address: ')
- begin_port = int(input('port to start scanning from: '))
- end_port = int(input('to :'))
- for port in range(begin_port, end_port, chunk):
- scan_chunk(host, port, min(end_port, port + chunk))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement