Last active
August 26, 2015 11:17
-
-
Save kirk91/87355e92289e6114e08c to your computer and use it in GitHub Desktop.
Auto get ss-link shadowsocks free accounts
This file contains hidden or 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 | |
# -*- coding:utf-8 -*- | |
import hashlib | |
import argparse | |
import json | |
import time | |
import requests | |
from bs4 import BeautifulSoup | |
from fabric.api import local | |
# ss-link | |
login_url = 'https://www.ss-link.com/login' | |
free_ss_account_url = 'https://www.ss-link.com/my/free' | |
def get_ss_link_free_accounts(email, password): | |
payload = { | |
'email': email, | |
'password': hashlib.md5(password).hexdigest(), | |
'redirect': free_ss_account_url, | |
} | |
resp = requests.post(login_url, data=payload) | |
if resp.status_code != requests.status_codes.codes.ok: | |
resp.raise_for_status() | |
soup = BeautifulSoup(resp.text, 'html.parser') | |
free_accounts = [] | |
for ss_account_record_node in soup.table.tbody.find_all('tr'): | |
sub_nodes = ss_account_record_node.find_all('td') | |
route = u'{}'.format(sub_nodes[0].string.strip()) | |
server_address = sub_nodes[1].string.strip() | |
server_port = int(sub_nodes[2].string.strip()) | |
server_password = sub_nodes[3].string.strip() | |
server_encrypt_method = sub_nodes[4].string.strip() | |
free_accounts.append( | |
{ | |
'route': route, | |
'server_address': server_address, | |
'server_port': server_port, | |
'server_password': server_password, | |
'server_encrypt_method': server_encrypt_method, | |
} | |
) | |
return free_accounts | |
def update_shadowsocks_confile(free_ss_accounts, confile_path=None): | |
if confile_path is None: | |
confile_path = '/etc/shadowsocks.json' | |
with open(confile_path) as f: | |
config = json.load(f) | |
config['password'] = free_ss_accounts[0]['server_password'] | |
with open(confile_path, 'w') as f: | |
json.dump(config, f) | |
print 'update {} done'.format(confile_path) | |
def main(): | |
parser = argparse.ArgumentParser( | |
description='Auto get ss-link free shadowsocks accounts.') | |
parser.add_argument('email', help='ss-link email') | |
parser.add_argument('password', help='ss-link passsword') | |
args = parser.parse_args() | |
free_ss_accounts = get_ss_link_free_accounts(args.email, args.password) | |
print "{:#^72}".format( | |
'{} Shadowsocks Accounts'.format(time.strftime('%Y-%m-%d %H:%M:%S'))) | |
print '{:<20} {:<12} {:<20} {}'.format( | |
'server_address', 'server_port', 'server_password', 'encrypt_method' | |
) | |
print '=' * 72 | |
for ss_account in free_ss_accounts: | |
print ('{server_address:<20} {server_port:^12} {server_password:^20} ' | |
'{server_encrypt_method:^18}').format(**ss_account) | |
print "\n{:#^72}".format(' Update Shadowsocks Config ') | |
# TODO test network speed | |
update_shadowsocks_confile(free_ss_accounts) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment