44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
|
#bash -c 'proxybroker --timeout 5 find --types HTTP HTTPS --lvl High --countries GB ES DE IT FR SW US RU --strict -l 25 --format json --outfile proxies.txt'
|
||
|
#sleep 5
|
||
|
# proxy=$(python choose_proxy.py proxies.txt)
|
||
|
#--proxy-server=socks5://127.0.0.1:9050
|
||
|
# DISPLAY=:1 all_proxy=true /usr/bin/google-chrome-stable --user-data-dir='./chrome-profile' --no-first-run --proxy-server=http://$proxy &
|
||
|
|
||
|
import sys
|
||
|
import json
|
||
|
import random
|
||
|
import requests
|
||
|
|
||
|
if len(sys.argv) > 2:
|
||
|
print("Too many arguments, only the file listing the proxies is needed", file=sys.stderr)
|
||
|
elif len(sys.argv) < 1:
|
||
|
print("Please input the json file containing the proxy list", file=sys.stderr)
|
||
|
else:
|
||
|
file = open(sys.argv[1])
|
||
|
|
||
|
string = ""
|
||
|
for line in file.readlines():
|
||
|
string += line
|
||
|
|
||
|
json_file = json.loads(string)
|
||
|
proxies = []
|
||
|
for i in json_file:
|
||
|
proxies.append(str(i['host']) + ":" + str(i['port']))
|
||
|
|
||
|
proxy_found = False
|
||
|
while proxy_found is False:
|
||
|
PROXY = proxies[random.randint(0,len(proxies)-1)]
|
||
|
# print("\nTrying to use {} as proxy".format(PROXY))
|
||
|
try:
|
||
|
r = requests.get('https://google.com', proxies={'https': 'http://{}'.format(PROXY), 'http': 'http://{}'.format(PROXY)}, timeout=3)
|
||
|
if r.status_code == 200:
|
||
|
# print('\n[+] IP Address used as proxy: ' + PROXY)
|
||
|
proxy_found = True
|
||
|
else:
|
||
|
# print('\nProxy is present but returned status code ' + str(r.status_code))
|
||
|
proxies.remove(PROXY)
|
||
|
except Exception as e:
|
||
|
# print('Failed with an exception: \n' + str(e))
|
||
|
proxies.remove(PROXY)
|
||
|
|
||
|
print(PROXY, file=sys.stdout)
|