Coder Social home page Coder Social logo

v2raygen's Introduction

XRayGen

Contributors Forks Stargazers Issues Telegram

V2RayGen/XRayGen: A Fast and Automated Script for XRay/V2Ray Server Setup

Usage

Quick Setup

Examples

Options

Block List

License

Donate Me

Prerequisites & Dependencies

  • Python3
  • Docker
  • Docker Compose

If your server lacks Docker and Docker-Compose, the script will install them and launch XRay-Core automatically.

use sudo if your current user is not in the docker group or you don't have docker installed

How Does XRayGen Work?

XRayGen uses Docker to retrieve the xray-core image from the Docker registry. It then generates a configuration file to launch the XRay container.

A client-side configuration file is also created for use with XRay-core or V2Ray-core.

The XRayAgent provides user management for XRay configuration, offering CRUD operations.

Usage

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | python3 - -h

Sample


QuickSetup

You can use one of the following protocols for installation and change its settings according to your needs.

Protoctol Argument
VMESS WS --vmess
VMESS WS TLS --vmess --tls
VMESS TCP --vmess --tcp
VMESS TCP TLS --vmess --tcp --tls
VLESS WS TLS --vless
VLESS TCP TLS --vless --tcp
VLESS TCP XTLS --vless --tcp --xtls
TROJAN WS TLS --trojan
TROJAN TCP TLS --trojan --tcp
TROJAN TCP XTLS --trojan --xtls
ShadowSocks TCP --shadowsocks
ShadowSocks TCP TLS --shadowsocks --tls

Quick Xray Setup with Default Setting :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vmess

OR

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py --output V2RayGen.py
sudo python3 V2RayGen.py --vmess

Sample

Use the provided link for your client, or use the client-side JSON configuration with XRay-Core or V2Ray-Core. If your server is on a domain, simply change the IP to your domain or subdomain after importing the link to your V2Ray client.

Examples

Setup XRAY / ShadowSocks :

VLESS :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vless

VMESS + TLS with blocking option :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vmess --tls --block

VMESS + TLS with blocking iranian domains and IPs option :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vmess --tls --blockir

VMESS + Changing client-side HTTP and SOCKS port :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vmess --chttp 4020 --csocks 8080

VMESS + TCP Network Stream :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vmess --tcp

VMESS + TCP Network Stream + TLS and QRCode :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vmess --tcp --tls --qrcode

VLESS + Using Google DNS :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vless --dns google

VLESS + TCP + XTLS :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vless --tcp --xtls

ShadowSocks + adding shadowsocks port to server :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --shadowsocks --firewall

Parsing Configuration :

Parse & reading Configuration file :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | python3 - --parseconfig config.json

Parse URL and read information :

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | python3 -  --parse vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJhaWQiOiIwIiwiaG9zdCI6IiIsImlkIjoiM2JlNjE2NzktOGQzOC00ZWJiLWJjOGItMTQ4ZjE0ZWY5ZTc3IiwibmV0Ijoid3MiLCJwYXRoIjoiL2dyYXBocWwiLCJwb3J0IjoiNDQzIiwicHMiOiJ4cmF5IiwidGxzIjoidGxzIiwidHlwZSI6Im5vbmUiLCJ2IjoiMiIgfQ==

XRayAgent

XRayAgent is a Simple User Management for XRay Configuration

Download Script & Run With Python3:

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py --output /tmp/v.py && python3 /tmp/v.py --agent

OR

curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/XRayAgent.py --output XRayAgent.py
python3 XRayAgent.py

By default it loads config.json for loading configuration

For loading other configuration simply enter the name of the configuration after XRayAgent.py :

python3 XRayAgent.py config.json

XRayAgent Commands :

  add, adduser                      Adding user
  update, updateuser                Update existing user with their index ID
  del, deluser                      Delete existing user with ther index ID
  users, listusers                  List of users

  deliptables, deleteiptables       Delete rules on server-side port
  climit , conlimit                 Add IP limitations on server-side port

  p, port                           Change server side port
  h, help                           Get help
  v, version                        Get version of program
  q, quit                           Exit program

after adding an user a index will be created for that user for example :

Index : 0 {'id': '25ad6df8-9a54-4f6e-8c44-d5685359a7ce', 'level': 0, 'email': '[email protected]'}
Index : 1 {'id': '62bf2d5d-766b-4281-963a-544449a26b4f', 'level': 0, 'email': '[email protected]'}

and now you can update that user with ther index ID :

cmd > : update 1
Index 1 Selected
Leave the section empty if you don't want to modify that section
New Email : test@gmail.com
New ID : 62bf2d5d-766b-4281-963a-544449a26b4f
Index 1 Updated
vless://62bf2d5d-766b-4281-963a-544449a26b4f@127.0.0.1:443?path=/graphql&security=tls&encryption=none&type=ws#xray

Use Index ID for update , del

For Showing list of Users and their Indexs use users or listusers command


IPTABLES Section :

using climit or conlimit limits the total connection ips on server side port

for deleting the all rules on server side port use deliptables or deleteiptables


Options

you can change server-side configuration with this options

Server Side

Protocols

vmess Creating vmess with default options.

vless Creating VLess with default options.

shadowsocks Creating ShadowSocks with default options.

you can combine arguments with default options to change the behavior of your configuration for example :

--vmess --port 8080 --tls --tcp --linkname TESTSERVER

this will create a vmess with port 8080 and self-signed tls , then gives a link with TESTSERVER name

Log & DNS Settings:

dns for using custom dns instead system's default dns configuration.

List of loglevels :

debug : Information for developers. All "Info" included.

info : Running stats of XRay,no effect for the functions. All "Warning"
included.

warning : usually some external problem that does not affect V2Ray but possibly the user experience.

error : XRay encountered a problem that needs to be resolved immediately.

none : Nothing will be printed.

ex :

--loglevel debug will set your logging level to debug mode

logs will be printed on your container docker. you can view the logs with docker logs <containerid>

Supported DNS providers:

list of avaliable dns's.

ex : --dns google will set your server side configuration dns to google

DNS
google
cloudflare
opendns
quad9
adguard

https://www.v2ray.com/en/configuration/dns.html

Routing Options

block for adding blocking Bittorrent and Ads.

blockir for Blocking Bittorrent, Ads and Iranian IPs in routing configuration.

The routing function module can send inbound data through different outbound connections according to different rules, so as to achieve the purpose of on-demand proxy.

For example, the common usage is to divert domestic and foreign traffic, Xray can judge the traffic in different regions through the internal mechanism, and then send them to different outbound proxies.

https://xtls.github.io/config/routing.html#routingobject

Inbounds

tls Using TLS in specified protocol

tls option can be used for any v2ray protocol for example :

--vmess --tls will create a vmess with self-signed tls

it's important to enable allow insecure tls on your client

xtls Using XTLS in specified protocol

XTLS only supports (TCP, mKCP) so by default when you use --xtls argument tcp mode is being used for vless

also xtls doesn't support vmess protocol

port for changing configuration port.

if you want your v2ray to be listening on a different port use this option

uuid for using custom uuid configuration.

by default random uuid will be generated. use this option if you want to have a custom uuid or existing uuid configuration

ex : --uuid ca33b7a2-26d6-47b1-a3c4-471425d868b9

id custom alterID.

insecure, Disable Insecure Encryption. [deprecated]

Stream Settings:

stream settings is the network type of the stream transport. and by default this script will use websocket for using it with nginx and cdn

tcp Using TCP network stream.

wspath Changing default WebSocket path configuration.

default web socket path is /graphql change it with this option.

ex :

--wspath /myservice

header Using custom header obfuscation configuration.

Make sure your header file look like the below JSON :

{
  "header": {
    "type": "http",
    "response": {
      "version": "1.1",
      "status": "200",
      "reason": "OK",
      "headers": {
        "Content-Type": [
          "application/octet-stream",
          "application/x-msdownload",
          "text/html",
          "application/x-shockwave-flash"
        ],
        "Transfer-Encoding": ["chunked"],
        "Connection": ["keep-alive"],
        "Pragma": "no-cache"
      }
    }
  }
}

header argument is useful when needing another http request configuration you can pass your http request configuration with this option.

--header request.json

Visit below site for HTTPRequest Object : https://www.v2ray.com/en/configuration/transport/tcp.html#httprequestobject

linkname for changing linkname after generating configuration.

Link formats :

VMess :
vmess://{"add":"ip / domain ","aid":"alterid","host":"","id":"random-uuid","net":"ws","path":"websocket-path","port":"80","ps":"linkname","tls":"","type":"none","v":"2" }
VLess :
vless://random-uuid@ip:port?path=websocketpath&security=type&encryption=none&type=ws#linkname
Trojan :
trojan://password@ip:port?allowInsecure=insecure&security=&type=networkstream#linkname
ShadowSocks :
ss://shadowsocks-security-method:random-uuid@domain/ip :port

Client Side

after generating the configuration with desired protocol client-side configuration is also generated as well

you can use client-side configuration directly with xray-core or v2ray-core

security security method for client-side configuration.

List of security methods :

  • aes-128-gcm
  • chacha20-poly1305
  • auto
  • none
  • zero

csocks client-side SOCKS port . default: [10808]

chttp client-side HTTP port . default: [10809]

qrcode Generate QRCode for generated link.

if you want to import your configuration with qrcode use this argument.

ShadowSocks

shadowsocks are loaded with xray docker container and it uses tcp stream for passing traffic

sspass set password for shadowsocks configuration file. by default, it uses a random password

ssmethod Set cipher method for ShadowSocks . default cipher method is 2022-blake3-chacha20-poly1305 to provide better security hence it's only usable in xray-core. for using shadowsocks with v2ray core use one of the below cipher methods :

V2Ray Cipher methods :

  • 2022-blake3-chacha20-poly1305
  • 2022-blake3-aes-256-gcm
  • 2022-blake3-aes-128-gcm

XRay Cipher methods :

  • 2022-blake3-chacha20-poly1305
  • 2022-blake3-aes-256-gcm
  • 2022-blake3-aes-128-gcm
  • xchacha20-ietf-poly1305

Parsing Configuration

for parsing existed configuration or decoding vmess url use below options :

parse for parsing encoded link. supported formats are [vmess://,ss://]

parseconfig for reading the configuration file and parsing information

--parseconfig config.json will show the information of the configuration and generate a QR code for that


Block List

Block lists are files that can be used in V2Ray clients that allow users to block or direct individual connections. These lists can be used to blacklist specific IP addresses or domains, or to whitelist trusted ones.

In some countries, such as Iran, authorities actively try to block access to VPN services by monitoring requests sent from foreign IP addresses to local servers. When such requests are detected, the associated IP addresses are added to a blacklist, effectively blocking access to VPNs. As a result, users in these countries may need to disable their VPN connection in order to access local websites without issue. Block lists can help circumvent these restrictions by allowing users to selectively block or redirect certain connections, thereby avoiding detection by authorities.

This files are avaliable under geodata directory

Block List Sources

The ads list is provided by the PersianBlocker list.

The iraninan CIDR is provided by the IP2Location site.


DonateMe

If this Project helped you, you can also help me by donation

tron-button   TTTo7aasobgqH5pKouCJfmPYn2KLed2RA3

bitcoin-button   bc1qgdav05s04qx99mdveuvdt76jauttcwdq687pc8

ethereum-button   0xD17dF52790f5D6Bf0b29151c7ABC4FFC4056f937

tether-button   0xD17dF52790f5D6Bf0b29151c7ABC4FFC4056f937

License

Licensed under the GPL-3 license.

v2raygen's People

Contributors

amirfrd avatar gharibkhani avatar mar-coding avatar sonyacore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

v2raygen's Issues

latest v2ray image

I think there is an issue related to the latest v2ray image published yesterday.
here are the docker logs:
flag provided but not defined: -config
Usage of /usr/bin/v2ray:_

AGPLv3 license violation

You're using the PersianBlockerHosts filterlists as a source to block ads:

ADS = Request("https://raw.githubusercontent.com/MasterKia/PersianBlocker/main/PersianBlockerHosts.txt")

That filterlist is licensed under the AGPLv3:
https://github.com/MasterKia/PersianBlocker/blob/main/PersianBlockerHosts.txt#L7

The GPL explicitly prohibits the removal of its license from files, and it appears that the listed files below do not contain any license header. Therefore, you should add the appropriate GPL license header to these files to ensure compliance with the license requirements:

https://github.com/SonyaCore/V2RayGen/blob/f0112dd42588959975f86fd9f4d3a84c4e7deafc/geodata/ads.txt

https://github.com/SonyaCore/V2RayGen/blob/f0112dd42588959975f86fd9f4d3a84c4e7deafc/geodata/clash_rules.yaml

https://github.com/SonyaCore/V2RayGen/blob/f0112dd42588959975f86fd9f4d3a84c4e7deafc/geodata/iran.dat

https://github.com/SonyaCore/V2RayGen/blob/f0112dd42588959975f86fd9f4d3a84c4e7deafc/geodata/qv2ray-client.json

The GPL also requires attribution, so please add something like this in your README file:

The ads list is provided by the PersianBlocker list:
https://github.com/MasterKia/PersianBlocker

Error on installing on Ubuntu 22.04

I am installling on Ubuntu 22.04 in Arvan. Any ideas of this error?

! VMess Config Generated.
! Created vmess-v2ray docker-compose.yml configuration
Docker Not Found.
Installing Docker ...
% Total % Received % XferdDload AverageUpload SpeedTotal Time Spent TimeLeft Time CurrentSpeed
0 0 0 0 0 0 0 0 --:--:-- 0:05:00 --:--:-- 0
curl: (28) Operation timed out after 300433 milliseconds with 0 out of 0 bytes received
Failed to enable unit: Unit file docker.service does not exist.
docker-compose Not Found.
Installing docker-compose v2.11.2 ...

After upgrading all the packages. The error changed to .

curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to get.docker.com:443
Failed to enable unit: Unit file docker.service does not exist.
docker-compose Not Found.
Installing docker-compose v2.11.2 ...

same id for xray

After some trying, I found out that in some circumstances, there is a chance that Xray creates same id for new users again and again.
fault

Cannot connect to the Docker daemon on Centos

On CentOS 9 Stream x64, I faced an error as:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Traceback (most recent call last):
File "", line 804, in
File "", line 435, in vmess_simple
File "", line 617, in run_docker
File "/usr/lib64/python3.9/subprocess.py", line 528, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'docker-compose -f docker-compose.yml up -d' returned non-zero exit status 1.

picture of the log attached.
image_2022-10-09_141248442

It was solved by systemctl start docker. You may want to include it somewhere.

Option to add custom UUID

It would be nice if we can pass the UUID as an argument.
This way, the same client settings would be valid on a fresh installation on the same IP.

UI suggestion

Hi,
How do you think about adding X-UI panel to your script so that the admin can manage the server and accounts easier.

Demote the logging level

Dear Sonya

Would you please demote the logging level in config.json to "error"? The default right now is "warning", that leads to bulky log files.

{
  "log": {
    "loglevel": "warning",
    "access": "/var/log/v2ray/access.log", // Your path of log in Linux
    "error": "/var/log/v2ray/error.log"
  },

Traffic limit suggestion

Hi Sonya
I use this wonderful script and thank you for it.
I want to share my configs with my friends, but I'm afraid that my configs will be exposed to the public (due to resources, bandwidth, etc.).
I tried the "conlimit" option in XRayAgent but it doesn't work for me.
It would be great and more functional if there was an option to limit traffic, like "Total traffic" in the X-UI panel.

Download Failed !

hi
iam run this command in ubuntu 20.04
curl https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/V2RayGen.py | sudo python3 - --vmess

and than i got this error:

! VMESS Config Generated.
! Created xray-core docker-compose.yml configuration
Docker Not Found.
Installing Docker ...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 19873 100 19873 0 0 497k 0 --:--:-- --:--:-- --:--:-- 497k

Executing docker install script, commit: 4f282167c425347a931ccfd95cc91fab041d414f

  • sh -c apt-get update -qq >/dev/null
    E: The repository 'http://deb.debian.org/debian $ Release' does not have a Release file.
    Download Failed !

why? how i can fix this?

error in add user config

root@proxy05:~# python3 XRayAgent.py

__   _______                                      _   
\ \ / /  __ \               /\                   | |  
 \ V /| |__) |__ _ _   _   /  \   __ _  ___ _ __ | |_ 
  > < |  _  // _` | | | | / /\ \ / _` |/ _ \ '_ \| __|
 / . \| | \ \ (_| | |_| |/ ____ \ (_| |  __/ | | | |_ 
/_/ \_\_|  \_\__,_|\__, /_/    \_\__, |\___|_| |_|\__|
                    __/ |         __/ |               
                   |___/         |___/                


Loaded Config : config.json
Docker Compose : ON
IP : 164.90.189.7
Protocol : vmess
PORT : 443

XRayAgent.py [options]
    USER Management :
    add, adduser                             Add user
    update, updateuser                       Update existing user
    del, deluser                             Delete existing user
    users, listusers                         List of users

    IPTables :
    deliptables, deleteiptables              Delete rules on server-side port
    climit , conlimit                        Add IP limitations on server-side port

    p, port                                  Change server side port
    h, help                                  Get help
    v, version                               Get version
    q, quit                                  Exit program

cmd > : add
! ADDING User
! Leave Sections Empty for Random Value
Email :[email protected]
ID / UUID : tj2ptj2;t3
AlterID 0 to 64 : 1
ADD user success! uuid: tj2ptj2;t3, alterId: 1, email : [email protected]
Traceback (most recent call last):
  File "/root/XRayAgent.py", line 772, in <module>
    commands["adduser"]()
  File "/root/XRayAgent.py", line 535, in create_user
    link_generator(data, -1)
  File "/root/XRayAgent.py", line 435, in link_generator
    security = data["inbounds"][0]["security"]
KeyError: 'security'
root@proxy05:~# 

unable to create docker-compose.yml

Version: V2RayGen latest version

Description:

Code which worked prior to creating docker-compose.yml is now might producing an error when generating config.

How to run multiple configs?

Hi
Many thanks for the awesome script it is super helpful for us. I have created multiple configs like vmess, vless ... but how can I run them?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.