v2gen

package module
v0.0.0-...-8e29766 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2020 License: MIT Imports: 20 Imported by: 0

README

v2gen

A powerful V2Ray config generator

You can use use vmess ping instead of ICMP ping

GitHub top language Go GitHub code size in bytes

简体中文

Preview

[ 0] 中继香港C1 Media (HK)(1)      [518ms  (0 errors)]
[ 1] 中继香港C3 Media (HK)(1)      [527ms  (0 errors)]
[ 2] 中继香港C2 Media (HK)(1)      [536ms  (0 errors)]
[ 3] 中继香港C5 Media (HK)(1)      [451ms  (0 errors)]
[ 4] 中继香港C6 Media (HK)(1)      [452ms  (0 errors)]
[ 5] 中继香港G2 Media (HK)(1)      [904ms  (0 errors)]
[ 6] BGP中继香港 2 Media (HK)(1)   [468ms  (0 errors)]
[ 7] BGP中继香港 3 Media (HK)(1)   [778ms  (0 errors)]
[ 8] BGP中继香港 1 Media (HK)(1)   [881ms  (0 errors)]
[ 9] 中继香港G1 Media (HK)(1)      [1.35s  (1 errors)]
...
[50] 日本中继 3 Media (JP)(1)      [641ms  (0 errors)]
=====================
Please Select:

How to use

Build it first

go get -u iochen.com/v2gen/cmd

or Download in GitHub Releases

Then run

v2gen -u {{Your subscription link}} -o {{Your V2Ray config path}}

Param

Usage of v2gen:
  -best
        use best node judged by ping result
  -c string
        v2gen config path (default "/etc/v2ray/v2gen.ini")
  -ct int
        ping count for each node (default 3)
  -dest string
        test destination url (vmess ping only) (default "https://cloudflare.com/cdn-cgi/trace")
  -eto int
        timeout seconds for each request (default 8)
  -ic
        use ICMP ping instead of vmess ping
  -init
        initialize v2gen config
  -med
        use median instead of ArithmeticMean
  -n int
        node index (default -1)
  -np
        do not ping
  -o string
        output path (default "/etc/v2ray/config.json")
  -r    random node index
  -sort
        sort ping results
  -t int
        threads used when pinging (default 5)
  -tpl string
        V2Ray tpl path
  -tto int
        timeout seconds for each node (default 25)
  -u string
        subscription URL
  -v    show version
  -vmess string
        vmess link(s)

V2Gen user config

You can use v2gen --init to generate one

# V2Ray log level
# ( debug | info | warning | error | none )
loglevel: warning

# Socks port
socksPort: 1080

# Http port
httpPort: 1081

# If allow UDP traffic
# ( true | false )
udp: true

# Security
# ( aes-128-gcm | aes-256-gcm | chacha20-poly1305 | auto | none )
security: aes-256-gcm

# If enable mux
# ( true | false )
mux: true

# Mux concurrency num
concurrency: 8

# DNS server
dns1: https://1.1.1.1/dns-query
dns2: https://dns.quad9.net/dns-query

# If China sites and ips directly connect
# ( true | false )
china: true

The following config may NOT work on every node

# If allow insecure connection ( true | false )
allowInsecure: false

# KCP mtu num
mtu: 1350

# KCP tti num
tti: 20

# KCP max upload speed
# Unit: MB/s
up: 5

# KCP max download speed
# Unit: MB/s
down: 20

# If enable UDP congestion control ( true | false )
congestion: false

# Read buffer size
# Unit: MB
readBufferSize: 1

# Write buffer size
# Unit: MB
writeBufferSize: 1

Version

V1.4.2

In case of any discrepancy or inconsistency between Version Number here and Tag, Tag shall prevail.

LINCENSE

MIT LICENSE

Notice

no support for version 1 format

Documentation

Index

Constants

View Source
const (
	TLSObject = `{
 		 "serverName": "{{address}}",
 		 "allowInsecure": {{allowInsecure}},
 		 "alpn": ["http/1.1"]
		}`

	WsObject = `{
 		 "path": "{{path}}",
 		 "headers": {
  		  "Host": "{{host}}"
 		 }
		}`

	KcpObject = `` /* 255-byte string literal not displayed */

	HttpObject = `{
		"host": [{{host}}],
		"path": "{{path}}"
		}`
	QuicObject = `{
		  "security": "{{host}}",
		  "key": "{{path}}",
		  "header": {
		    "type": "{{type}}"
		  }
		}`
)
View Source
const ChinaSites = `
{
	"type": "field",
	"outboundTag": "direct",
    "domain": ["geosite:cn"] 
},`
View Source
const ConfigTpl = `` /* 1453-byte string literal not displayed */
View Source
const DefaultV2GenConf = `` /* 1301-byte string literal not displayed */

Variables

View Source
var (
	FlagURL      = flag.String("u", "", "subscription URL")
	FlagPath     = flag.String("o", "/etc/v2ray/config.json", "output path")
	FlagUserConf = flag.String("c", "/etc/v2ray/v2gen.ini", "v2gen config path")
	FlagTPL      = flag.String("tpl", "", "V2Ray tpl path")
	FlagURIs     = flag.String("vmess", "", "vmess link(s)")
	FlagInit     = flag.Bool("init", false, "initialize v2gen config")
	FlagIndex    = flag.Int("n", -1, "node index")
	FlagRandom   = flag.Bool("r", false, "random node index")
	FlagNoPing   = flag.Bool("np", false, "do not ping")
	FlagDest     = flag.String("dest", "https://cloudflare.com/cdn-cgi/trace", "test destination url (vmess ping only)")
	FlagCount    = flag.Int("ct", 3, "ping count for each node")
	FlagETO      = flag.Int("eto", 8, "timeout seconds for each request")
	FlagTTO      = flag.Int("tto", 25, "timeout seconds for each node")
	FlagICMP     = flag.Bool("ic", false, "use ICMP ping instead of vmess ping")
	FlagMedian   = flag.Bool("med", false, "use median instead of ArithmeticMean")
	FlagThreads  = flag.Int("t", 5, "threads used when pinging")
	FlagSort     = flag.Bool("sort", false, "sort ping results")
	FlagBest     = flag.Bool("best", false, "use best node judged by ping result")
	FlagVersion  = flag.Bool("v", false, "show version")
)

Functions

func GenConf

func GenConf(Settings map[string]string) ([]byte, error)

func GenFromSecRawData

func GenFromSecRawData(secRawData string) error

func GenFromURL

func GenFromURL(URL string) error

func GenSettings

func GenSettings(node vmess.Link, userConfPath string) map[string]string

func GetUserConf

func GetUserConf(path string) map[string]string

func GetVmessList

func GetVmessList(secDataList []string) *[]vmess.Link

func InitV2GenConf

func InitV2GenConf(p string) error

func MakeNode

func MakeNode(k int, v vmess.Link, waitList *int, npCh chan NodePingStatus, doneCh chan bool)

func ParseHost

func ParseHost(s string) string

from "aaa.ltd,bbb.ltd" to ""aaa.ltd","bbb.ltd""

func ParseV2GenConf

func ParseV2GenConf(b []byte) map[string]string

func Ping

func Ping(lk *vmess.Link) (*ping.Status, error)

func PrettyPrint

func PrettyPrint(b []byte) ([]byte, error)

func Pri2Sec

func Pri2Sec(priData string) []string

func PrintNode

func PrintNode(i int, vmessList *[]vmess.Link, np *NodePingStatus)

func SecRaw2Sec

func SecRaw2Sec(secRawData string) []string

func SelectNode

func SelectNode(vmessList *[]vmess.Link) (int, error)

func URL2Pri

func URL2Pri(URL string) string

Types

type NodePingStatus

type NodePingStatus struct {
	Index    int
	PingStat *ping.Status
	Result   ping.Duration
	Err      error
}

type NodeStatusList

type NodeStatusList []NodePingStatus

func PingNodes

func PingNodes(lks *[]vmess.Link, print bool) *NodeStatusList

func (*NodeStatusList) Len

func (sList *NodeStatusList) Len() int

func (*NodeStatusList) Less

func (sList *NodeStatusList) Less(i, j int) bool

func (*NodeStatusList) Swap

func (sList *NodeStatusList) Swap(i, j int)

Directories

Path Synopsis
app
cmd
common
infra

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL