Skip to content

Commit

Permalink
Merge pull request FunctionClub#61 from bzd111/master
Browse files Browse the repository at this point in the history
fix bugs
  • Loading branch information
zyh001 authored Aug 4, 2019
2 parents 4816007 + 64669c9 commit 8459f78
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 8 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ verify_ssl = true

[dev-packages]
yapf = "*"
flake8 = "*"

[packages]
requests = ">=2.20.0"
Expand Down
263 changes: 263 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions Config_Generator.py → config_generator.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import json
import urllib2
import commands
import json

import requests
from requests.exceptions import ConnectTimeout


def getip():
myip = urllib2.urlopen('https://cn.fdos.me/ip.php').read()
myip = myip.strip()
return str(myip)
try:
resp = requests.get("http://httpbin.org/ip", timeout=5).json()
ip = resp.get("origin").split(", ")[1]
except ConnectTimeout:
import socket
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
return str(ip)


def open_port(port):
Expand Down
8 changes: 5 additions & 3 deletions init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import config_generator
import uuid

data = {}
with open("/usr/local/V2ray.Fun/v2ray.config") as f:
data = json.load(f)
try:
data = json.load(f)
except ValueError:
data = {}

data['uuid'] = str(uuid.uuid4())
data['ip'] = config_generator.getip()
config_generator.open_port(data['port'])

with open("/usr/local/V2ray.Fun/v2ray.config", "w") as f:
f.write(json.dump(data))
json.dump(data, f)

config_generator.gen_server()
config_generator.gen_client()

0 comments on commit 8459f78

Please sign in to comment.