Advertisement
Guest User

Untitled

a guest
Aug 25th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. from socket import socket
  2. from select import select
  3.  
  4. tmout = 1
  5. chunk = 300
  6.  
  7. def scan_chunk(host, begin_port, end_port):
  8.     socks = []
  9.     for port in range(begin_port, end_port):
  10.         sock = socket()
  11.         sock.setblocking(False)
  12.         try:
  13.             sock.connect((host, port))
  14.         except BlockingIOError:
  15.             pass
  16.         socks.append(sock)
  17.     r, w, x = select([], socks, [], tmout)
  18.     for sock in w:
  19.         port = sock.getpeername()[1]
  20.         print(port, 'connected')
  21.     for sock in socks:
  22.         sock.close()
  23.    
  24. host = input('address: ')
  25. begin_port = int(input('port to start scanning from: '))
  26. end_port = int(input('to :'))
  27.  
  28. for port in range(begin_port, end_port, chunk):
  29.     scan_chunk(host, port, min(end_port, port + chunk))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement