Compare commits
2 Commits
88a5898f8c
...
1931445c13
Author | SHA1 | Date | |
---|---|---|---|
1931445c13 | |||
816b07306f |
178
old/utool.py
Executable file
178
old/utool.py
Executable file
@ -0,0 +1,178 @@
|
||||
#!/usr/bin/python3
|
||||
# coding: utf-8
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
c_title = '\033[1;4;31;42m' # title color
|
||||
c_br = '\033[1;31m' # bold red
|
||||
c_bg = '\033[1;32m' # bold green
|
||||
c_by = '\033[1;33m' # bold yellow
|
||||
c_bb = '\033[1;34m' # bold blue
|
||||
c_bp = '\033[1;35m' # bold purple
|
||||
c_bc = '\033[1;36m' # bold cyan
|
||||
c_bir= '\033[1;3;31m' # * bold italic red
|
||||
c_bib = '\033[1;3;34m' # * bold italic cyan
|
||||
c_bic = '\033[1;3;36m' # bold italic cyan
|
||||
c_e = '\033[0m' # reset
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
opt_1 = sys.argv[1]
|
||||
opt_rest = None
|
||||
elif len(sys.argv) > 2:
|
||||
opt_1 = sys.argv[1]
|
||||
opt_rest = sys.argv[2:]
|
||||
else:
|
||||
opt_1 = None
|
||||
opt_rest = None
|
||||
|
||||
opt_index = ['-do_not_use_this', '-a', '-b', '-c', '-d', '-e', '-f', '-g', '-h', '-i', '-j', '-k', '-l', '-m',
|
||||
'-n', '-o', '-p', '-q', '-r', '-s', '-t', '-u', '-v', '-w', '-x', '-y', '-z']
|
||||
|
||||
if opt_1 not in opt_index:
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/usage.sh')
|
||||
exit(100)
|
||||
|
||||
if opt_1 == '-a':
|
||||
if opt_rest != None:
|
||||
print(f"This option({opt_1}) will print all ports of now using for local, and accept NO parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/ipports.sh port')
|
||||
|
||||
elif opt_1 == '-b':
|
||||
if opt_rest != None:
|
||||
print(f"This option({opt_1}) will generate a two-factor auth-key for github login, and accept NO parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
os.system("/usr/bin/oathtool -b --totp 'G3NHHFO2L2LZ5W2R'")
|
||||
|
||||
elif opt_1 == '-c':
|
||||
if opt_rest != None:
|
||||
print(f"This option({opt_1}) will print all intranet IP using in docker, and accept NO parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/ipports.sh ip')
|
||||
|
||||
elif opt_1 == '-d':
|
||||
if opt_rest != None:
|
||||
print(f"This option({opt_1}) will return the current IP of local machine, and accept NO parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
os.system("/usr/bin/python3 /opt/scripts/roll_api/get_self_ip.py")
|
||||
|
||||
elif opt_1 == '-e':
|
||||
if opt_rest == None:
|
||||
print(f"This option({opt_1}) will return the IP info, and accept at least one IP parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
for opt_2 in opt_rest:
|
||||
os.environ['opt_2'] = opt_2
|
||||
os.system('/usr/bin/python3 /opt/scripts/roll_api/get_ip.py $opt_2')
|
||||
|
||||
elif opt_1 == '-f':
|
||||
if len(sys.argv) < 3:
|
||||
print(f"{c_br}需要至少一个字符串作为输入,退出...{c_e}\n")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
param=''
|
||||
for item in sys.argv[2:]:
|
||||
param += item
|
||||
|
||||
os.environ['param'] = param
|
||||
print(f"{c_by}Warning: 输入字符串中间的任何空白符将会被删除,要保留的话,需手动将字符串用单引号括起来{c_e}")
|
||||
print(f"本次计算MD5值的字符串为 - {param}\n本次计算得到的MD5的值为 - ", end='')
|
||||
# print(f"本次计算得到的MD5的值为 - ", end='')
|
||||
os.system('echo -n $param | md5sum | cut -d " " -f 1')
|
||||
|
||||
elif opt_1 == '-g':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-h':
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/usage.sh')
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-i':
|
||||
if opt_rest == None:
|
||||
print(f"This option({opt_1}) will return the domain registration info, and accept at least one domain parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
for opt_2 in opt_rest:
|
||||
os.environ['opt_2'] = opt_2
|
||||
os.system('/usr/bin/python3 /opt/scripts/roll_api/domain_reg_check.py $opt_2')
|
||||
|
||||
elif opt_1 == '-j':
|
||||
if len(sys.argv) == 2:
|
||||
print(f"{c_br}-j选项:将十进制或者十六进制数字作为入参,转换成标准时间格式,只接收第一个参数,其他参数将被丢弃,有歧义时,使用'0x'或者'0X'来区分十进制和十六进制,退出...{c_e}\n")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
os.environ['param'] = sys.argv[2]
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/number2d.sh $param')
|
||||
|
||||
elif opt_1 == '-k':
|
||||
if len(sys.argv) < 3:
|
||||
print(f"{c_br}-k选项:将输入的时间转换成十进制和十六进制,需要一个字符串格式的时间作为输入,退出...{c_e}\n")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
param=''
|
||||
for item in sys.argv[2:]:
|
||||
param += item + ' '
|
||||
|
||||
os.environ['param'] = param
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/date2n.sh $param')
|
||||
|
||||
elif opt_1 == '-l':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-m':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-n':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-o':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-p':
|
||||
if opt_rest == None:
|
||||
opt_rest = ['',]
|
||||
|
||||
opt_2 = opt_rest[0]
|
||||
os.environ['opt_2'] = opt_2
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/genpw.sh $opt_2')
|
||||
|
||||
elif opt_1 == '-q':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-r':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-s':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-t':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-u':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-v':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-w':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-x':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-y':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-z':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
else:
|
||||
print("This line SHOULD NOT be executed, please check carefully.")
|
||||
exit(255)
|
||||
|
||||
|
||||
|
272
utool/utool.py
272
utool/utool.py
@ -4,175 +4,125 @@ import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
c_title = '\033[1;4;31;42m' # title color
|
||||
c_br = '\033[1;31m' # bold red
|
||||
c_bg = '\033[1;32m' # bold green
|
||||
c_by = '\033[1;33m' # bold yellow
|
||||
c_bb = '\033[1;34m' # bold blue
|
||||
c_bp = '\033[1;35m' # bold purple
|
||||
c_bc = '\033[1;36m' # bold cyan
|
||||
c_bir= '\033[1;3;31m' # * bold italic red
|
||||
c_bib = '\033[1;3;34m' # * bold italic cyan
|
||||
c_bic = '\033[1;3;36m' # bold italic cyan
|
||||
c_e = '\033[0m' # reset
|
||||
def utool(option):
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
opt_1 = sys.argv[1]
|
||||
opt_rest = None
|
||||
elif len(sys.argv) > 2:
|
||||
opt_1 = sys.argv[1]
|
||||
opt_rest = sys.argv[2:]
|
||||
else:
|
||||
opt_1 = None
|
||||
opt_rest = None
|
||||
def print_usage():
|
||||
intro = """utool -- a self-defined command line interface, which is used to facilitate operating the system, supports the following options. In the description part, where there is a leading asterisk signifies that this option must take an argument, and for more information of this situation, simply run `utool -h` for details."""
|
||||
print(f"{c_intro}{intro}{c_e}")
|
||||
print("_" * 121)
|
||||
print(f"{c_title}|Option| Description{' ' * 40}|Option| Description{' ' * 40}|{c_e}")
|
||||
count = 0
|
||||
for opt, desc in dict_func.items():
|
||||
description = "" if desc[0] == "Reserved" else desc[0]
|
||||
if count % 2 == 0:
|
||||
print(f"{c_text}|{opt:^6}|{description:<52}{c_e}", end="")
|
||||
else:
|
||||
print(f"{c_text}|{opt:^6}|{description:<52}|{c_e}")
|
||||
count += 1
|
||||
exit(100)
|
||||
|
||||
opt_index = ['-do_not_use_this', '-a', '-b', '-c', '-d', '-e', '-f', '-g', '-h', '-i', '-j', '-k', '-l', '-m',
|
||||
'-n', '-o', '-p', '-q', '-r', '-s', '-t', '-u', '-v', '-w', '-x', '-y', '-z']
|
||||
# -a
|
||||
def list_local_using_port():
|
||||
exit_on_wrong_number()
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/ipports.sh port')
|
||||
|
||||
if opt_1 not in opt_index:
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/usage.sh')
|
||||
exit(100)
|
||||
# -b
|
||||
def github_two_factor():
|
||||
exit_on_wrong_number()
|
||||
os.system("/usr/bin/oathtool -b --totp 'G3NHHFO2L2LZ5W2R'")
|
||||
|
||||
if opt_1 == '-a':
|
||||
if opt_rest != None:
|
||||
print(f"This option({opt_1}) will print all ports of now using for local, and accept NO parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
# -c
|
||||
def get_external_ip():
|
||||
exit_on_wrong_number()
|
||||
os.system("/usr/bin/python3 /opt/scripts/roll_api/get_self_ip.py")
|
||||
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/ipports.sh port')
|
||||
# -d
|
||||
def get_ip_location():
|
||||
exit_on_wrong_number(2)
|
||||
import re
|
||||
checked_ip = sys.argv[2]
|
||||
ipv4 = re.match(r"^((([01]?\d\d?)|(2[0-4]\d)|(25[0-5]))\.){3}(([01]?\d\d?)|(2[0-4]\d)|(25[0-5]))$", checked_ip)
|
||||
if ipv4:
|
||||
os.environ['checked_ip'] = checked_ip
|
||||
os.system('/usr/bin/python3 /opt/scripts/roll_api/get_ip.py $checked_ip')
|
||||
else:
|
||||
print(f"{c_br}Plz enter correct IP...{c_e}")
|
||||
exit(ord(option.strip('-')))
|
||||
|
||||
elif opt_1 == '-b':
|
||||
if opt_rest != None:
|
||||
print(f"This option({opt_1}) will generate a two-factor auth-key for github login, and accept NO parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
os.system("/usr/bin/oathtool -b --totp 'G3NHHFO2L2LZ5W2R'")
|
||||
def exit_on_wrong_number(number=1):
|
||||
if len(sys.argv) != (number+1):
|
||||
print(f"{c_br}{sys.argv[1:]}: Wrong arguments!")
|
||||
print(f"Option `{option}' will {dict_func[option][0].strip()}")
|
||||
print(f"NEED: {number}\tGIVE: {len(sys.argv)-1}\n{c_e}")
|
||||
exit(ord(option.strip('-')))
|
||||
|
||||
elif opt_1 == '-c':
|
||||
if opt_rest != None:
|
||||
print(f"This option({opt_1}) will print all intranet IP using in docker, and accept NO parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/ipports.sh ip')
|
||||
|
||||
elif opt_1 == '-d':
|
||||
if opt_rest != None:
|
||||
print(f"This option({opt_1}) will return the current IP of local machine, and accept NO parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
os.system("/usr/bin/python3 /opt/scripts/roll_api/get_self_ip.py")
|
||||
|
||||
elif opt_1 == '-e':
|
||||
if opt_rest == None:
|
||||
print(f"This option({opt_1}) will return the IP info, and accept at least one IP parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
for opt_2 in opt_rest:
|
||||
os.environ['opt_2'] = opt_2
|
||||
os.system('/usr/bin/python3 /opt/scripts/roll_api/get_ip.py $opt_2')
|
||||
|
||||
elif opt_1 == '-f':
|
||||
if len(sys.argv) < 3:
|
||||
print(f"{c_br}需要至少一个字符串作为输入,退出...{c_e}\n")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
param=''
|
||||
for item in sys.argv[2:]:
|
||||
param += item
|
||||
|
||||
os.environ['param'] = param
|
||||
print(f"{c_by}Warning: 输入字符串中间的任何空白符将会被删除,要保留的话,需手动将字符串用单引号括起来{c_e}")
|
||||
print(f"本次计算MD5值的字符串为 - {param}\n本次计算得到的MD5的值为 - ", end='')
|
||||
# print(f"本次计算得到的MD5的值为 - ", end='')
|
||||
os.system('echo -n $param | md5sum | cut -d " " -f 1')
|
||||
|
||||
elif opt_1 == '-g':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-h':
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/usage.sh')
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-i':
|
||||
if opt_rest == None:
|
||||
print(f"This option({opt_1}) will return the domain registration info, and accept at least one domain parameter.")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
for opt_2 in opt_rest:
|
||||
os.environ['opt_2'] = opt_2
|
||||
os.system('/usr/bin/python3 /opt/scripts/roll_api/domain_reg_check.py $opt_2')
|
||||
|
||||
elif opt_1 == '-j':
|
||||
if len(sys.argv) == 2:
|
||||
print(f"{c_br}-j选项:将十进制或者十六进制数字作为入参,转换成标准时间格式,只接收第一个参数,其他参数将被丢弃,有歧义时,使用'0x'或者'0X'来区分十进制和十六进制,退出...{c_e}\n")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
os.environ['param'] = sys.argv[2]
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/number2d.sh $param')
|
||||
|
||||
elif opt_1 == '-k':
|
||||
if len(sys.argv) < 3:
|
||||
print(f"{c_br}-k选项:将输入的时间转换成十进制和十六进制,需要一个字符串格式的时间作为输入,退出...{c_e}\n")
|
||||
exit(opt_index.index(opt_1))
|
||||
|
||||
param=''
|
||||
for item in sys.argv[2:]:
|
||||
param += item + ' '
|
||||
|
||||
os.environ['param'] = param
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/date2n.sh $param')
|
||||
|
||||
elif opt_1 == '-l':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-m':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-n':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-o':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-p':
|
||||
if opt_rest == None:
|
||||
opt_rest = ['',]
|
||||
|
||||
opt_2 = opt_rest[0]
|
||||
os.environ['opt_2'] = opt_2
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/genpw.sh $opt_2')
|
||||
|
||||
elif opt_1 == '-q':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-r':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-s':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-t':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-u':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-v':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-w':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-x':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-y':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
elif opt_1 == '-z':
|
||||
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
|
||||
exit(opt_index.index(opt_1))
|
||||
else:
|
||||
print("This line SHOULD NOT be executed, please check carefully.")
|
||||
exit(255)
|
||||
dict_func = {
|
||||
'-a': [' print all local ports of using for now', list_local_using_port],
|
||||
'-n': ['Reserved', None],
|
||||
'-b': [' generate two-factor key of GITHUB', github_two_factor],
|
||||
'-o': ['Reserved', None],
|
||||
'-c': [' show external IP of this machine', get_external_ip],
|
||||
'-p': ['Reserved', None],
|
||||
'-d': [' show the location of ip(only v4 for now)', get_ip_location],
|
||||
'-q': ['Reserved', None],
|
||||
'-e': ['Reserved', None],
|
||||
'-r': ['Reserved', None],
|
||||
'-f': ['Reserved', None],
|
||||
'-s': ['Reserved', None],
|
||||
'-g': ['Reserved', None],
|
||||
'-t': ['Reserved', None],
|
||||
'-h': ['Reserved', print_usage],
|
||||
'-u': ['Reserved', None],
|
||||
'-i': ['Reserved', None],
|
||||
'-v': ['Reserved', None],
|
||||
'-j': ['Reserved', None],
|
||||
'-w': ['Reserved', None],
|
||||
'-k': ['Reserved', None],
|
||||
'-x': ['Reserved', None],
|
||||
'-l': ['Reserved', None],
|
||||
'-y': ['Reserved', None],
|
||||
'-m': ['Reserved', None],
|
||||
'-z': ['Reserved', None],
|
||||
}
|
||||
return dict_func[option][1]
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
global option
|
||||
options = [ '-' + chr(x) for x in range(ord('a'), ord('z')+1)]
|
||||
print_usage = utool('-h')
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
option = sys.argv[1]
|
||||
if option in options:
|
||||
func = utool(option)
|
||||
if func == None:
|
||||
print(f"{c_bg}Option `{option}' is reserved for now...{c_e}\n")
|
||||
else:
|
||||
func()
|
||||
else:
|
||||
print_usage()
|
||||
else:
|
||||
print_usage()
|
||||
|
||||
c_title = '\033[1;4;37;40m' # title color
|
||||
c_text = '\033[37;40m' # text color
|
||||
c_intro = '\033[3;32m' # text color
|
||||
c_br = '\033[1;31m' # bold red
|
||||
c_bg = '\033[1;32m' # bold green
|
||||
c_by = '\033[1;33m' # bold yellow
|
||||
c_bb = '\033[1;34m' # bold blue
|
||||
c_bp = '\033[1;35m' # bold purple
|
||||
c_bc = '\033[1;36m' # bold cyan
|
||||
c_bir= '\033[1;3;31m' # * bold italic red
|
||||
c_bib = '\033[1;3;34m' # * bold italic cyan
|
||||
c_bic = '\033[1;3;36m' # bold italic cyan
|
||||
c_e = '\033[0m' # reset
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user