scripts/old/utool.py

179 lines
6.4 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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)