Created
October 21, 2018 16:30
-
-
Save smellslikeml/fa7b5ed546bc6b92fdc7f1e10e4e800b to your computer and use it in GitHub Desktop.
tor_proxy_file_request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from urllib.request import urlretrieve, ProxyHandler, build_opener, install_opener | |
def check_ip(): | |
current_ip = requests.get( | |
url='http://icanhazip.com/', | |
proxies=socks_proxy, | |
verify=False | |
) | |
return current_ip.text | |
def download_img(img_lst, img_dir='/path/to/imgs/'): | |
for img in img_lst: | |
filename = img.split('/')[-1] | |
try: | |
urlretrieve(img, os.path.join(img_dir, filename)) | |
except: | |
pass | |
if __name__ == '__main__': | |
import sys | |
local_proxy = 'socks5://localhost:9050' | |
socks_proxy = { | |
'http': local_proxy, | |
'https': local_proxy | |
} | |
print(check_ip()) | |
proxy = ProxyHandler({'http': '127.0.0.1:9050'}) | |
opener = build_opener(proxy) | |
imgs_file = sys.argv[1] | |
with open(imgs_file, 'r') as infile: | |
data = infile.readlines() | |
img_lst = [img.strip() for img in img_lst] | |
download_img(img_lst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment