Skip to content

Commit

Permalink
support change port dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
tracyone committed May 1, 2018
1 parent ce3e9fc commit c29fb5b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
17 changes: 17 additions & 0 deletions en_dyn_port.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import readjson
import writejson
from utils import is_number


#主要程序部分
print ("是否使能动态端口(y/n)")
newport=raw_input()
if newport == 'y':
writejson.EnDynPort(1)
elif newport == 'n':
writejson.EnDynPort(0)
else:
print ("输入错误,请检查是否为数字")

21 changes: 19 additions & 2 deletions json_template/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"loglevel": "info"
},
"inbound": {
"port": 1234,
"port": 12345,
"listen": null,
"protocol": "vmess",
"settings": {
Expand Down Expand Up @@ -80,7 +80,24 @@
"streamSettings": null,
"mux": null
},
"inboundDetour": null,
"inboundDetour":[
{
"protocol": "vmess",
"port": "10000-20000",
"tag": "dynamicPort",
"settings": {
"default": {
"level": 1,
"alterId": 32
}
},
"allocate": {
"strategy": "random",
"concurrency": 2,
"refresh": 5
}
}
],
"outboundDetour": [
{
"protocol": "freedom",
Expand Down
10 changes: 9 additions & 1 deletion v2ray
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ if [[ ${choice} == 2 ]]; then
echo "5.更改TLS设置"
echo "6.更改广告拦截功能"
echo "7.更改alterId"
echo "8.更改动态端口"
echo "请输入数字选择功能:"

while :; do echo
read -n1 -p "请选择: " changechoice
if [[ ! $changechoice =~ ^[1-7]$ ]]; then
if [[ ! $changechoice =~ ^[1-8]$ ]]; then
if [[ -z ${changechoice} ]];then
bash /usr/local/bin/v2ray
exit 0
Expand All @@ -101,6 +102,13 @@ if [[ ${choice} == 2 ]]; then
break
fi
done
if [[ ${changechoice} == 8 ]]; then
python /usr/local/v2ray.fun/en_dyn_port.py
service v2ray restart
echo ""
echo "更改动态端口成功!"
bash /usr/local/bin/v2ray
fi
if [[ ${changechoice} == 7 ]]; then
python /usr/local/v2ray.fun/change_alter_ID.py
python /usr/local/v2ray.fun/genclient.py
Expand Down
10 changes: 9 additions & 1 deletion writejson.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ def Write():
openjsonfile=file("/etc/v2ray/config.json","w+")
openjsonfile.writelines(myjsondump)
openjsonfile.close()


def EnDynPort(en):
if en == 1:
config[u"inbound"][u"settings"].update({u"detour":{u"to":"dynamicPort"}})
else:
if "detour" in config[u"inbound"][u"settings"]:
del config[u"inbound"][u"settings"][u"detour"]
Write()

#更改UUID
def WriteUUID(myuuid):
config[u"inbound"][u"settings"][u"clients"][0][u"id"]=str(myuuid)
Expand Down

0 comments on commit c29fb5b

Please sign in to comment.