Browse Source

feat: add udp and ipv6 port support

master
Dnomd343 3 years ago
parent
commit
3ad98ee370
  1. 2
      ProxyBuilder/__init__.py
  2. 31
      ProxyBuilder/main.py

2
ProxyBuilder/__init__.py

@ -3,4 +3,4 @@
from ProxyBuilder.main import build from ProxyBuilder.main import build
from ProxyBuilder.main import check from ProxyBuilder.main import check
from ProxyBuilder.main import destroy from ProxyBuilder.main import destroy

31
ProxyBuilder/main.py

@ -17,19 +17,30 @@ libcPaths = [
'/lib/libc.musl-x86_64.so.1', # Alpine '/lib/libc.musl-x86_64.so.1', # Alpine
] ]
# TODO: TCP/UDP IPv4/IPv6 def __checkPortAvailable(port): # 检测端口可用性
def __checkPortAvailable(port, host = '127.0.0.1'): # 检测端口可用性
s = None
try: try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ipv4_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1) ipv4_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((host, int(port))) ipv4_tcp.bind(('0.0.0.0', port))
return False ipv4_udp.bind(('0.0.0.0', port))
except socket.error: ipv4_tcp.close()
ipv4_udp.close()
ipv6_tcp = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
ipv6_udp = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
ipv6_tcp.bind(('::', port))
ipv6_udp.bind(('::', port))
ipv6_tcp.close()
ipv6_udp.close()
return True return True
except:
return False
finally: finally:
if s: try:
s.close() if ipv4_tcp: ipv4_tcp.close()
if ipv4_udp: ipv4_udp.close()
if ipv6_tcp: ipv6_tcp.close()
if ipv6_udp: ipv6_udp.close()
except: pass
def __genTaskFlag(length = 16): # 生成任务代号 def __genTaskFlag(length = 16): # 生成任务代号
flag = "" flag = ""

Loading…
Cancel
Save