1 import base64 2 3 def base64_decode(s): 4 num=len(s)%4 5 if num==0: 6 s=base64.urlsafe_b64decode(s) 7 else: 8 s=s+'='*(4-num) 9 s=base64.urlsafe_b64decode(s) 10 return s.decode('utf-8') 11 12 def parse_ssr(base64_encode_str): 13 ssr_config={} 14 base64_encode_str=base64_encode_str[6:] 15 secrypt_str=base64_decode(base64_encode_str) 16 split_str=secrypt_str.split(':') 17 18 ssr_config['server']=split_str[0] 19 ssr_config['server_port']=int(split_str[1]) 20 ssr_config['protocol']=split_str[2] 21 ssr_config['method']=split_str[3] 22 ssr_config['obfs']=split_str[4] 23 24 password_and_parms=split_str[5].split('/?') 25 pwd_str=base64_decode(password_and_parms[0]) 26 ssr_config['password']=pwd_str 27 28 params=password_and_parms[1] 29 parms_part=params.split('&') 30 for x in parms_part: 31 key_and_value=x.split('=') 32 ssr_config[key_and_value[0]]=base64_decode(key_and_value[1]) 33 34 for k,v in ssr_config.items(): 35 print(k+"->"+str(v)) 36 print(len(ssr_config)) 37 38 if __name__ == "__main__": 39 ssr_url='ssr://xxxxxxxxx' 40 parse_ssr(ssr_url)