forked from XX-net/XX-Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
41 lines (32 loc) · 883 Bytes
/
Copy pathutils.py
File metadata and controls
41 lines (32 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import re
import os
g_ip_check = re.compile(r'^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$')
def check_ip_valid(ip):
ret = g_ip_check.match(ip)
if ret is not None:
"each item range: [0,255]"
for item in ret.groups():
if int(item) > 255:
return 0
return 1
else:
return 0
def str2hex(data):
out_list = []
if isinstance(data, bytes):
data1 = data.decode('iso-8859-1')
for c in data1:
#print(c)
cc = ord(c)
ccc = "{:02x}".format(cc)
out_list.append(ccc)
out_str = ":".join(out_list)
return out_str
def generate_random_lowercase(n):
min_lc = ord(b'a')
len_lc = 26
ba = bytearray(os.urandom(n))
for i, b in enumerate(ba):
ba[i] = min_lc + b % len_lc # convert 0..255 to 97..122
#sys.stdout.buffer.write(ba)
return ba