惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
月光博客
月光博客
博客园_首页
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AWS News Blog
AWS News Blog
S
Securelist
T
Tailwind CSS Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
罗磊的独立博客
D
Docker
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
H
Help Net Security
Project Zero
Project Zero
P
Proofpoint News Feed
D
DataBreaches.Net
Recorded Future
Recorded Future
Simon Willison's Weblog
Simon Willison's Weblog
V2EX - 技术
V2EX - 技术
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
I
Intezer
Engineering at Meta
Engineering at Meta
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
S
Secure Thoughts
GbyAI
GbyAI
U
Unit 42
Blog — PlanetScale
Blog — PlanetScale
T
Threat Research - Cisco Blogs
The Last Watchdog
The Last Watchdog
Y
Y Combinator Blog
F
Fortinet All Blogs
博客园 - Franky
T
The Blog of Author Tim Ferriss
Hacker News: Ask HN
Hacker News: Ask HN
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone

Feed of liolok

Fix Broken URLs of My Site Containerize Steam with systemd-nspawn Containerize Android Studio with systemd-nspawn Run Desktop App with systemd-nspawn Container Oculus Quest 2 Usage Note Set Environment Variables with pam_env Install Arch Linux on Acer Swift 3 SF313-52 Run Mastodon Server on Arch Linux VPS Manage Dotfiles with Git and Stow Run SS and MTProxy Server on AWS How to Add Image to Hexo Blog Post Build Blog with Hexo and GitHub Pages
V2Ray Subscription Parse
2019-11-18 · via Feed of liolok

cd ~{,/zhs/}

Preface

V2Ray core doesn’t provide subscription feature, this is cool because it’s considered unnecessary to people who self-host just one or several V2Ray services. If using service bought from websites, however, one may have to find a client with subscribe support to get a better user experience.

Up to now, there are several subscription formats; I’m gonna explore to resolve some of them on my own demand, using Python or even other languages.

V2RayN Format

Source documentation

  • Subscription url: a regular url (http / https);
  • Return content of subscription url: a list of share link, separated by newline, at last encoded using Base64;
  • Support schemes: vmess, ss and socks.

Example:

vmess://base64(Configuration)
ss://base64(Configuration)
socks://base64(Configuration)

Get Content from Subscription Url

HOWTO Fetch Internet Resources Using The urllib Package — Python 3.8.0 documentation

from urllib.request import urlopen
subscribe_url = 'https://input-your-own-v2rayn-format-subscribe-url-here'
return_content = urlopen(subscribe_url).read()
print(return_content)

Now we should get a really long string that seems random, like this:

Base64 Example

base64 — Base16, Base32, Base64, Base85 Data Encodings — Python 3.8.0 documentation

from base64 import b64decode
share_links = b64decode(return_content).decode('utf-8').splitlines()
print(share_links)

This step we get a list of share link string:

Share Links

Get Configurations

from urllib.parse import urlsplit
import json
schemes_allow = ['vmess', 'ss', 'socks']
configs = []
for share_link in share_links:
    url = urlsplit(share_link)
    if url.scheme not in schemes_allow: raise RuntimeError('invalid share link')
    configs.append(json.loads(b64decode(url.netloc).decode('utf-8')))
print(configs)

Note: You may have to add padding to url.netloc.

Finally we get a list of json objects, each of them contains a server configuraion:

Configurations