Skip to content

Instantly share code, notes, and snippets.

@leVirve
Last active June 2, 2017 11:38
Show Gist options
  • Save leVirve/96f680a9b690468c7e1a9aeb734bb524 to your computer and use it in GitHub Desktop.
Save leVirve/96f680a9b690468c7e1a9aeb734bb524 to your computer and use it in GitHub Desktop.
A script for proxy get.
#!/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))
@leVirve
Copy link
Author

leVirve commented Jun 2, 2017

Usage

  • Fill in your user@ip in Line#7

  • Download file through script

    ./sget.py {Some URL here}

@leVirve
Copy link
Author

leVirve commented Jun 2, 2017

 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