parse-ss-url.py
· 363 B · Python
Ham
def parse_url(url):
scheme, loc, path, query, frag = urlsplit(url)
if not scheme == "ss":
return None
secret, addr = loc.split("@")
if not ":" in secret:
secret = base64.urlsafe_b64decode(secret)
cipher, key = secret.split(":")
host, port = addr.split(":")
frag = unquote(frag)
return host, port, cipher, key, frag
| 1 | def parse_url(url): |
| 2 | scheme, loc, path, query, frag = urlsplit(url) |
| 3 | if not scheme == "ss": |
| 4 | return None |
| 5 | secret, addr = loc.split("@") |
| 6 | if not ":" in secret: |
| 7 | secret = base64.urlsafe_b64decode(secret) |
| 8 | cipher, key = secret.split(":") |
| 9 | host, port = addr.split(":") |
| 10 | frag = unquote(frag) |
| 11 | return host, port, cipher, key, frag |
| 12 |