mirror of https://github.com/dnomd343/ProxyC
dnomd343
2 years ago
6 changed files with 63 additions and 62 deletions
@ -1,9 +1,27 @@ |
|||||
#!/usr/bin/env python3 |
#!/usr/bin/env python3 |
||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from IPy import IP |
||||
from Utils.Logger import logger |
from Utils.Logger import logger |
||||
from Utils.Common.Coding import * |
from Utils.Common.Coding import * |
||||
|
|
||||
|
|
||||
|
def v6AddBracket(host: str) -> str: # add bracket for ipv6 |
||||
|
return hostFormat(host, v6Bracket = True) |
||||
|
|
||||
|
|
||||
|
def hostFormat(host: str, v6Bracket: bool = False) -> str: |
||||
|
try: |
||||
|
if host[:1] == '[' and host[-1:] == ']': # [IPv6] format |
||||
|
host = host[1:-1] # remove extra bracket |
||||
|
ip = IP(host) |
||||
|
if v6Bracket and ip.version() == 6: |
||||
|
return '[%s]' % str(ip) # [IPv6] |
||||
|
return str(ip) # IPv4 / IPV6 |
||||
|
except: # not ip address |
||||
|
return host |
||||
|
|
||||
|
|
||||
def checkScheme(url: str, scheme: str, name: str) -> str: # check url scheme and remove it |
def checkScheme(url: str, scheme: str, name: str) -> str: # check url scheme and remove it |
||||
if not url.startswith('%s://' % scheme): |
if not url.startswith('%s://' % scheme): |
||||
logger.warning('%s url should start with `%s://`' % (name, scheme)) |
logger.warning('%s url should start with `%s://`' % (name, scheme)) |
@ -0,0 +1,29 @@ |
|||||
|
#!/usr/bin/env python3 |
||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
import uuid |
||||
|
import random |
||||
|
import hashlib |
||||
|
from Utils.Logger import logger |
||||
|
|
||||
|
|
||||
|
def md5Sum(string: str) -> str: |
||||
|
return hashlib.md5(string.encode(encoding = 'utf-8')).hexdigest() # md5 hash |
||||
|
|
||||
|
|
||||
|
def genUUID() -> str: # generate uuid v5 |
||||
|
return str(uuid.uuid5( |
||||
|
uuid.NAMESPACE_DNS, genFlag(length = 16) |
||||
|
)) |
||||
|
|
||||
|
|
||||
|
def genFlag(length: int = 12) -> str: # generate random task flag |
||||
|
flag = '' |
||||
|
for i in range(0, length): |
||||
|
tmp = random.randint(0, 15) |
||||
|
if tmp >= 10: |
||||
|
flag += chr(tmp + 87) # a ~ f |
||||
|
else: |
||||
|
flag += str(tmp) # 0 ~ 9 |
||||
|
logger.debug('Generate new flag -> %s' % flag) |
||||
|
return flag |
@ -1,20 +0,0 @@ |
|||||
#!/usr/bin/env python3 |
|
||||
# -*- coding: utf-8 -*- |
|
||||
|
|
||||
from IPy import IP |
|
||||
|
|
||||
|
|
||||
def v6AddBracket(host: str) -> str: # add bracket for ipv6 |
|
||||
return hostFormat(host, v6Bracket = True) |
|
||||
|
|
||||
|
|
||||
def hostFormat(host: str, v6Bracket: bool = False) -> str: |
|
||||
try: |
|
||||
if host[:1] == '[' and host[-1:] == ']': # [IPv6] |
|
||||
host = host[1:-1] # remove extra bracket |
|
||||
ip = IP(host) |
|
||||
if v6Bracket and ip.version() == 6: |
|
||||
return '[%s]' % str(ip) # [IPv6] |
|
||||
return str(ip) # IPv4 / IPV6 |
|
||||
except: # not ip address |
|
||||
return host |
|
@ -1,6 +1,8 @@ |
|||||
#!/usr/bin/env python3 |
#!/usr/bin/env python3 |
||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
from Utils.Common.Url import * |
from Utils.Common.Type import * |
||||
from Utils.Common.Host import * |
from Utils.Common.Check import * |
||||
|
from Utils.Common.Format import * |
||||
from Utils.Common.Network import * |
from Utils.Common.Network import * |
||||
|
from Utils.Common.Generate import * |
||||
|
Loading…
Reference in new issue