Browse Source

style: CRLF to LF

master
dnomd343 2 years ago
parent
commit
a7dc63bf9d
  1. 130
      Basis/Functions.py
  2. 300
      ProxyTester/VMess.py

130
Basis/Functions.py

@ -1,65 +1,65 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
import psutil import psutil
import random import random
from Basis.Logger import logging from Basis.Logger import logging
def genFlag(length: int = 12) -> str: # generate random task flag def genFlag(length: int = 12) -> str: # generate random task flag
flag = '' flag = ''
for i in range(0, length): for i in range(0, length):
tmp = random.randint(0, 15) tmp = random.randint(0, 15)
if tmp >= 10: if tmp >= 10:
flag += chr(tmp + 87) # a ~ f flag += chr(tmp + 87) # a ~ f
else: else:
flag += str(tmp) # 0 ~ 9 flag += str(tmp) # 0 ~ 9
logging.debug('generate new flag -> ' + flag) logging.debug('generate new flag -> ' + flag)
return flag return flag
def getAvailablePort(rangeStart: int = 41952, rangeEnd: int = 65535) -> int: # get a available port def getAvailablePort(rangeStart: int = 41952, rangeEnd: int = 65535) -> int: # get a available port
if rangeStart > rangeEnd or rangeStart < 1 or rangeEnd > 65535: if rangeStart > rangeEnd or rangeStart < 1 or rangeEnd > 65535:
raise RuntimeError('invalid port range') raise RuntimeError('invalid port range')
while True: while True:
port = random.randint(rangeStart, rangeEnd) # choose randomly port = random.randint(rangeStart, rangeEnd) # choose randomly
if checkPortStatus(port): if checkPortStatus(port):
logging.debug('get new port -> %i' % port) logging.debug('get new port -> %i' % port)
return port return port
time.sleep(0.1) # wait for 100ms time.sleep(0.1) # wait for 100ms
def checkPortStatus(port: int) -> bool: # check if the port is occupied def checkPortStatus(port: int) -> bool: # check if the port is occupied
logging.debug('check status of port %i -> available' % port) logging.debug('check status of port %i -> available' % port)
for connection in networkStatus(): # scan every connections for connection in networkStatus(): # scan every connections
if connection['local']['port'] == port: # port occupied (whatever ipv4-tcp / ipv4-udp / ipv6-tcp / ipv6-udp) if connection['local']['port'] == port: # port occupied (whatever ipv4-tcp / ipv4-udp / ipv6-tcp / ipv6-udp)
logging.debug('check status of port %i -> occupied' % port) logging.debug('check status of port %i -> occupied' % port)
return False return False
return True return True
def networkStatus() -> list: # get all network connections def networkStatus() -> list: # get all network connections
result = [] result = []
for connection in psutil.net_connections(): for connection in psutil.net_connections():
if not connection.family.name.startswith('AF_INET'): # AF_INET / AF_INET6 if not connection.family.name.startswith('AF_INET'): # AF_INET / AF_INET6
continue continue
if connection.type.name not in ['SOCK_STREAM', 'SOCK_DGRAM']: # TCP / UDP if connection.type.name not in ['SOCK_STREAM', 'SOCK_DGRAM']: # TCP / UDP
continue continue
result.append({ result.append({
'fd': connection.fd, 'fd': connection.fd,
'family': 'ipv6' if connection.family.name[-1] == '6' else 'ipv4', # ip version 'family': 'ipv6' if connection.family.name[-1] == '6' else 'ipv4', # ip version
'type': 'tcp' if connection.type.name == 'SOCK_STREAM' else 'udp', # tcp or udp 'type': 'tcp' if connection.type.name == 'SOCK_STREAM' else 'udp', # tcp or udp
'local': { # local bind address 'local': { # local bind address
'addr': connection.laddr.ip, 'addr': connection.laddr.ip,
'port': connection.laddr.port, 'port': connection.laddr.port,
}, },
'remote': { # remote address 'remote': { # remote address
'addr': connection.raddr.ip, 'addr': connection.raddr.ip,
'port': connection.raddr.port, 'port': connection.raddr.port,
} if len(connection.raddr) != 0 else None, } if len(connection.raddr) != 0 else None,
'status': connection.status, 'status': connection.status,
'pid': connection.pid, # process id 'pid': connection.pid, # process id
}) })
logging.debug('get network status -> found %i connections' % len(result)) logging.debug('get network status -> found %i connections' % len(result))
return result return result

300
ProxyTester/VMess.py

@ -1,150 +1,150 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
from ProxyTester import V2ray from ProxyTester import V2ray
testConfig = {} testConfig = {}
vmessMethodList = [ vmessMethodList = [
'aes-128-gcm', 'aes-128-gcm',
'chacha20-poly1305', 'chacha20-poly1305',
'auto', 'auto',
'none', 'none',
'zero', 'zero',
] ]
def vmessBasicTest(method: str, alterId: int) -> dict: def vmessBasicTest(method: str, alterId: int) -> dict:
inboundConfig = { inboundConfig = {
'protocol': 'vmess', 'protocol': 'vmess',
'listen': testConfig['bind'], 'listen': testConfig['bind'],
'port': testConfig['port'], 'port': testConfig['port'],
'settings': { 'settings': {
'clients': [ 'clients': [
{ {
'id': testConfig['id'], 'id': testConfig['id'],
'alterId': alterId 'alterId': alterId
} }
] ]
} }
} }
caption = 'VMess method ' + method caption = 'VMess method ' + method
if alterId == 0: if alterId == 0:
envVar = {} envVar = {}
caption += ' (AEAD)' caption += ' (AEAD)'
else: else:
envVar = { envVar = {
'v2ray.vmess.aead.forced': 'false' 'v2ray.vmess.aead.forced': 'false'
} }
caption += ' (alterId ' + str(alterId) + ')' caption += ' (alterId ' + str(alterId) + ')'
return { return {
'caption': caption, 'caption': caption,
'proxy': { 'proxy': {
'type': 'vmess', 'type': 'vmess',
'server': testConfig['addr'], 'server': testConfig['addr'],
'port': testConfig['port'], 'port': testConfig['port'],
'method': method, 'method': method,
'id': testConfig['id'], 'id': testConfig['id'],
'aid': alterId 'aid': alterId
}, },
'server': { 'server': {
'startCommand': ['v2ray', '-c', testConfig['file']], 'startCommand': ['v2ray', '-c', testConfig['file']],
'fileContent': V2ray.v2rayConfig(inboundConfig), 'fileContent': V2ray.v2rayConfig(inboundConfig),
'filePath': testConfig['file'], 'filePath': testConfig['file'],
'envVar': envVar 'envVar': envVar
}, },
'aider': None 'aider': None
} }
def loadVmessStream(streamInfo: dict) -> dict: def loadVmessStream(streamInfo: dict) -> dict:
proxyInfo = { proxyInfo = {
'type': 'vmess', 'type': 'vmess',
'server': testConfig['addr'], 'server': testConfig['addr'],
'port': testConfig['port'], 'port': testConfig['port'],
'id': testConfig['id'], 'id': testConfig['id'],
'stream': streamInfo['client'] 'stream': streamInfo['client']
} }
inboundConfig = { inboundConfig = {
'protocol': 'vmess', 'protocol': 'vmess',
'listen': testConfig['bind'], 'listen': testConfig['bind'],
'port': testConfig['port'], 'port': testConfig['port'],
'settings': { 'settings': {
'clients': [ 'clients': [
{ {
'id': testConfig['id'] 'id': testConfig['id']
} }
] ]
}, },
'streamSettings': streamInfo['server'] 'streamSettings': streamInfo['server']
} }
return { return {
'caption': 'VMess network ' + streamInfo['caption'], 'caption': 'VMess network ' + streamInfo['caption'],
'proxy': proxyInfo, 'proxy': proxyInfo,
'server': { 'server': {
'startCommand': ['v2ray', '-c', testConfig['file']], 'startCommand': ['v2ray', '-c', testConfig['file']],
'fileContent': V2ray.v2rayConfig(inboundConfig), 'fileContent': V2ray.v2rayConfig(inboundConfig),
'filePath': testConfig['file'], 'filePath': testConfig['file'],
'envVar': {} 'envVar': {}
}, },
'aider': None 'aider': None
} }
def test(config: dict) -> list: def test(config: dict) -> list:
global testConfig global testConfig
testConfig = config testConfig = config
testList = [] testList = []
# Basic test # Basic test
for method in vmessMethodList: # methods and AEAD/MD5+AES test for method in vmessMethodList: # methods and AEAD/MD5+AES test
testList.append(vmessBasicTest(method, 0)) testList.append(vmessBasicTest(method, 0))
testList.append(vmessBasicTest(method, 64)) testList.append(vmessBasicTest(method, 64))
# TCP stream # TCP stream
streamInfo = V2ray.loadTcpStream(False, '', '') streamInfo = V2ray.loadTcpStream(False, '', '')
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host'])
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
streamInfo = V2ray.loadTcpStream(True, config['host'], '/') streamInfo = V2ray.loadTcpStream(True, config['host'], '/')
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host'])
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
# mKCP stream # mKCP stream
for obfs in V2ray.udpObfsList: for obfs in V2ray.udpObfsList:
streamInfo = V2ray.loadKcpStream(config['passwd'], obfs) streamInfo = V2ray.loadKcpStream(config['passwd'], obfs)
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host'])
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
# WebSocket stream # WebSocket stream
streamInfo = V2ray.loadWsStream(config['host'], config['path'], False) streamInfo = V2ray.loadWsStream(config['host'], config['path'], False)
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host'])
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
streamInfo = V2ray.loadWsStream(config['host'], config['path'], True) streamInfo = V2ray.loadWsStream(config['host'], config['path'], True)
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host'])
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
# HTTP/2 stream # HTTP/2 stream
streamInfo = V2ray.loadH2Stream(config['host'], config['path']) streamInfo = V2ray.loadH2Stream(config['host'], config['path'])
streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host'])
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
# QUIC stream # QUIC stream
for method in V2ray.quicMethodList: for method in V2ray.quicMethodList:
for obfs in V2ray.udpObfsList: for obfs in V2ray.udpObfsList:
streamInfo = V2ray.loadQuicStream(method, config['passwd'], obfs) streamInfo = V2ray.loadQuicStream(method, config['passwd'], obfs)
streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host'])
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
# GRPC stream # GRPC stream
streamInfo = V2ray.loadGrpcStream(config['service']) streamInfo = V2ray.loadGrpcStream(config['service'])
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = V2ray.addSecureConfig(streamInfo, config['cert'], config['key'], config['host'])
testList.append(loadVmessStream(streamInfo)) testList.append(loadVmessStream(streamInfo))
return testList return testList

Loading…
Cancel
Save