Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, time, os
- import requests as req
- from threading import Thread, active_count
- counter = 0
- def open_file(file_name):
- if file_name is not None:
- try:
- with open(file_name, 'r') as f:
- data = f.readlines()
- return data[0].split()
- except FileNotFoundError:
- print('File "%s" is not found.' % file_name)
- sys.exit(2)
- return None
- def split(lst, n):
- return [lst[i::n] for i in range(n)]
- def func(ips, Country_Count):
- global counter
- proxy = '183.88.52.251:8080'
- proxies = ({'http':'http://'+proxy,
- 'https':'http://'+proxy})
- # proxies = ({'http':'socks5://login:pass@183.88.52.251:8080',
- # 'https':'socks5://login:pass@183.88.52.251:8080'})
- with req.Session() as s:
- s.proxies.update(proxies)
- for ip in ips:
- resp = s.get('http://api.db-ip.com/v2/free/'+ip).json()
- if resp.get('errorCode'):
- print(resp['error'])
- else:
- if Country_Count.get(resp['countryName']) is None:
- Country_Count.update({resp['countryName']: 1})
- else:
- Country_Count.update({resp['countryName']: Country_Count[resp['countryName']] + 1})
- counter += 1
- def show_result(dct):
- os.system('cls') if sys.platform == 'win32' else os.system('clear')
- print("Result: ")
- for k, v in sorted(dct.items(), key=lambda kv: kv[1])[::-1]:
- print(r'County: {}, Procent: {}'.format(k, v))
- def main():
- os.system('cls') if sys.platform == 'win32' else os.system('clear')
- Country_Count = {}
- ips = open_file('lst.txt')
- count_ips = len(ips)
- ct = 10
- ips = split(ips, ct)
- for x in range(ct):
- Thread(target=func, args=(ips[x], Country_Count)).start()
- while active_count() - 1 != 0:
- print('Scanning: %s/%s' % (counter, count_ips), end='\r')
- time.sleep(1)
- show_result(Country_Count)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement