Advertisement
aex-

Clean Random IP Port Scanner

Feb 24th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. import os
  2. import sys
  3. import random
  4. import threading
  5. import time
  6. import string
  7. import socket
  8.  
  9. thread_tid = []
  10.  
  11. def get_session_thread():
  12.     global thread_tid
  13.     stid = "".join(random.choice(string.lowercase + string.digits) for x in range(4))
  14.     return stid
  15.  
  16. def run_threads(hosts):
  17.     failure_code = "failure"
  18.     success_code = "success"
  19.     try:
  20.         sock = socket.socket()
  21.         socket.setdefaulttimeout(1)
  22.         result = sock.connect_ex((hosts, 22))
  23.         if (result == 0):
  24.             return success_code
  25.             sock.close()
  26.         else:
  27.             return failure_code
  28.             sock.close()
  29.     except socket.error:
  30.         return failure_code
  31.  
  32. def process_threads():
  33.     global thread_tid
  34.  
  35.     while True:
  36.         oct1 = random.randint(1, 254)
  37.         oct2 = random.randint(1, 254)
  38.         oct3 = random.randint(1, 254)
  39.         oct4 = random.randint(1, 254)
  40.  
  41.         final = str(oct1) + "." + str(oct2) + "." + str(oct3) + "." + str(oct4)
  42.  
  43.         thread_id = get_session_thread()
  44.         status_code = run_threads(final)
  45.         print("{:<25}: {:.4} | {:.7}".format(final, thread_id, status_code))
  46.         if (status_code == "success"):
  47.             f = open("a.out", "a").write(final+'\n')
  48.  
  49.         elif (status_code == "failure"):
  50.             pass
  51.  
  52. process_threads()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement