summaryrefslogtreecommitdiff
path: root/keyword/common/customlibrary/ipandstring/stringip.py
diff options
context:
space:
mode:
author董晓燕 <[email protected]>2021-06-03 09:55:45 +0000
committer董晓燕 <[email protected]>2021-06-03 09:55:45 +0000
commitac68e65f508799a0e555a240ae374d313a0a8d75 (patch)
tree2a339bbd8acd65e2fb235159cc9c5303ae5725b7 /keyword/common/customlibrary/ipandstring/stringip.py
parent2f39b56d617e5fba2b8d73d81cd5e6d894f85352 (diff)
parent4667c668725ff7cb673c637a297c67283876d4d4 (diff)
Merge branch 'develop' into 'master'HEADmaster
Develop See merge request dongxiaoyan/gap_tsg_api!4
Diffstat (limited to 'keyword/common/customlibrary/ipandstring/stringip.py')
-rw-r--r--keyword/common/customlibrary/ipandstring/stringip.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/keyword/common/customlibrary/ipandstring/stringip.py b/keyword/common/customlibrary/ipandstring/stringip.py
new file mode 100644
index 0000000..0ce0c44
--- /dev/null
+++ b/keyword/common/customlibrary/ipandstring/stringip.py
@@ -0,0 +1,68 @@
+import random
+import struct
+import socket
+
+class stringandip (object):
+ def __init__(self):
+ pass
+ def ipv4(self,m, n, x):
+ if m == '-1':
+ m = random.randint(0, 255)
+ if n == '-1':
+ n = random.randint(0, 255)
+ if x == '-1':
+ x = random.randint(0, 255)
+ y = random.randint(0, 255)
+ print(str(m) + '.' + str(n) + '.' + str(x) + '.' + str(y))
+ return str(m) + '.' + str(n) + '.' + str(x) + '.' + str(y)
+
+ def dec2hex(self,string_num):
+ base = [str(x) for x in range(10)] + [chr(x) for x in range(ord('A'), ord('A') + 6)]
+ num = int(string_num)
+ mid = []
+ while True:
+ if num == 0: break
+ num, rem = divmod(num, 16)
+ mid.append(base[rem])
+
+ return ''.join([str(x) for x in mid[::-1]])
+
+ def ipv6(self):
+ ipInt = random.randint(0, 400000000000000000000000000000000000)
+ ipStr = ''
+ leftValue = ipInt
+
+ for i in [7, 6, 5, 4, 3, 2, 1, 0]:
+ string_num = leftValue / 65536 ** i
+ base = [str(x) for x in range(10)] + [chr(x) for x in range(ord('A'), ord('A') + 6)]
+ num = int(string_num)
+ mid = []
+ while True:
+ if num == 0: break
+ num, rem = divmod(num, 16)
+ mid.append(base[rem])
+
+ ipTokenInt = ''.join([str(x) for x in mid[::-1]])
+ if (ipTokenInt == ''):
+ ipTokenInt = 0
+ ipStr = ipStr + str(ipTokenInt)
+ if i != 0:
+ ipStr = ipStr + ':'
+ leftValue %= 65536 ** i
+ print(ipStr)
+ return ipStr
+
+ def getstring(self,randomlength=16,base_str='ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'):
+ """
+ 生成一个指定长度的随机字符串
+ """
+ random_str = ''
+ #base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'
+ length = len(base_str) - 1
+ for i in range(randomlength):
+ random_str += base_str[random.randint(0, length)]
+ print(random_str)
+ return random_str
+# if __name__ == '__main__':
+# ipandstring = ipandstring()
+# print(ipandstring.ipv6()) \ No newline at end of file