daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import sys, time, os
  3. import requests as req
  4. from threading import Thread, active_count
  5.  
  6. counter = 0
  7.  
  8. def open_file(file_name):
  9.     if file_name is not None:
  10.         try:
  11.             with open(file_name, 'r') as f:
  12.                 data = f.readlines()
  13.  
  14.             return data[0].split()
  15.         except FileNotFoundError:
  16.             print('File "%s" is not found.' % file_name)
  17.             sys.exit(2)
  18.     return None
  19.  
  20. def split(lst, n):
  21.     return [lst[i::n] for i in range(n)]
  22.  
  23. def func(ips, Country_Count):
  24.     global counter
  25.     proxy = '183.88.52.251:8080'
  26.     proxies = ({'http':'http://'+proxy,
  27.                 'https':'http://'+proxy})
  28.  
  29.     # proxies = ({'http':'socks5://login:pass@183.88.52.251:8080',
  30.     #           'https':'socks5://login:pass@183.88.52.251:8080'})
  31.     with req.Session() as s:
  32.         s.proxies.update(proxies)
  33.         for ip in ips:
  34.             resp = s.get('http://api.db-ip.com/v2/free/'+ip).json()
  35.             if resp.get('errorCode'):
  36.                 print(resp['error'])
  37.             else:
  38.                 if Country_Count.get(resp['countryName']) is None:
  39.                     Country_Count.update({resp['countryName']: 1})
  40.                 else:
  41.                     Country_Count.update({resp['countryName']: Country_Count[resp['countryName']] + 1})
  42.                 counter += 1
  43.  
  44.  
  45. def show_result(dct):
  46.     os.system('cls') if sys.platform == 'win32' else os.system('clear')
  47.     print("Result: ")
  48.     for k, v in sorted(dct.items(), key=lambda kv: kv[1])[::-1]:
  49.         print(r'County: {},          Procent: {}'.format(k, v))
  50.  
  51. def main():
  52.     os.system('cls') if sys.platform == 'win32' else os.system('clear')
  53.     Country_Count = {}
  54.  
  55.     ips = open_file('lst.txt')
  56.     count_ips = len(ips)
  57.  
  58.     ct = 10
  59.     ips = split(ips, ct)
  60.     for x in range(ct):
  61.         Thread(target=func, args=(ips[x], Country_Count)).start()
  62.  
  63.     while active_count() - 1 != 0:
  64.         print('Scanning: %s/%s' % (counter, count_ips), end='\r')
  65.         time.sleep(1)
  66.  
  67.     show_result(Country_Count)
  68.  
  69.  
  70.  
  71. if __name__ == '__main__':
  72.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top