Last active
June 2, 2017 11:38
-
-
Save leVirve/96f680a9b690468c7e1a9aeb734bb524 to your computer and use it in GitHub Desktop.
A script for proxy get.
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
#!/usr/bin/env python | |
import os | |
import sys | |
import time | |
import requests | |
remote_server = '{user}@{ip}' | |
port = 9487 | |
proxies = { | |
'http': 'socks5://localhost:%d' % port, | |
'https': 'socks5://localhost:%d' % port} | |
def stream_download(stream_resp): | |
filename = stream_resp.headers.get('content-disposition') | |
filename = filename or os.path.basename(stream_resp.url) | |
with open(filename, 'wb') as f: | |
for chunk in stream_resp.iter_content(chunk_size=1024): | |
if chunk: | |
f.write(chunk) | |
return filename | |
try: | |
target = sys.argv[1] | |
s = time.time() | |
resp = requests.get(target, proxies=proxies, stream=True) | |
fn = stream_download(resp) | |
print('%s downloaded in %.4f sec'% (fn, time.time() - s)) | |
except requests.exceptions.InvalidSchema: | |
print('Make sure to run `pip install requests[socks]` first.') | |
except requests.exceptions.ConnectionError: | |
print('Make sure to run `ssh -D {} -fqCN {}` before this script.'.format( | |
port, remote_server)) |
curl --socks5-hostname 127.0.0.1:9487 -O {URL}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Fill in your
user@ip
inLine#7
Download file through script