84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
import json
|
|
import os
|
|
import time
|
|
|
|
|
|
# info_1 = os.popen('inotifywait -e modify /var/log/wtmp > /dev/null').readlines()
|
|
# print(info_1)
|
|
|
|
info_1 = os.popen('curl -s https://api.ipify.org').readlines()
|
|
print(info_1[0])
|
|
|
|
info_2 = os.popen("hostname -I | awk '{print $1}' ORS=''").readlines()
|
|
print(info_2[0])
|
|
|
|
info_3 = os.popen("cat /etc/os-release | grep '^ID=' | awk -F '=' '{print $2}' ORS=''").readlines()
|
|
info_4 = os.popen("""cat /etc/os-release | grep '^VERSION=' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}' ORS=''""").readlines()
|
|
info_5 = os.popen("uname -m").readlines()
|
|
print(info_3[0]+ ' ' +info_4[0] + ' ' +info_5[0])
|
|
|
|
info_6 = os.popen("'echo $SSH_CONNECTION' ORS=''").readlines()
|
|
print(info_6)
|
|
print(type(info_6))
|
|
if not info_6:
|
|
login_method = '其他登陆方式'
|
|
else:
|
|
login_method = 'SSH登陆'
|
|
|
|
last = os.popen('last -n 1').readlines()
|
|
print(last[0])
|
|
print(last[0].split()[0])
|
|
print(last[0].split()[1])
|
|
print(last[0].split()[2])
|
|
|
|
output = os.popen('last -n 1').readlines()
|
|
login_info = output[0].split()
|
|
login_time = login_info[3] + ' ' + login_info[4] + ' ' + login_info[5] + ' ' + login_info[6]
|
|
print("Login Time:", login_time)
|
|
print(login_info[7]+ ' ' + login_info[8] + ' ' + login_info[9])
|
|
|
|
geoip = os.popen(f"curl -s 'http://ip-api.com/json/10.168.1.159'").readlines()
|
|
print(geoip)
|
|
geoip_json = geoip[0]
|
|
geoip = json.loads(geoip_json)
|
|
print(type(geoip))
|
|
if geoip['status'] == 'fail':
|
|
print(geoip['message'])
|
|
elif geoip['status'] == 'success':
|
|
print(geoip['country'],geoip["regionName"], geoip["city"])
|
|
text = geoip['country']+' '+geoip["regionName"]+' '+geoip["city"]
|
|
|
|
server_info = {
|
|
"server_name": 'server_name',
|
|
"server_ip": info_1[0]+'(外) '+info_2[0]+'(内)',
|
|
"server_info": info_3[0]+ ' ' +info_4[0] + ' ' +info_5[0],
|
|
"login_method": login_method,
|
|
}
|
|
|
|
print(server_info)
|
|
|
|
|
|
from translate import Translator
|
|
|
|
def translate_english_to_chinese(text):
|
|
translator = Translator(to_lang="zh")
|
|
translation = translator.translate(text)
|
|
return translation
|
|
|
|
english_text = "Hello, how are you?"
|
|
chinese_text = translate_english_to_chinese(english_text)
|
|
# print(chinese_text)
|
|
# print(translate_english_to_chinese(geoip['message']))
|
|
# print(translate_english_to_chinese(text))
|
|
|
|
|
|
lastlog = os.popen('lastlog').readlines()
|
|
print(lastlog)
|
|
print(type(lastlog))
|
|
print(lastlog[0])
|
|
lastlog = os.popen('lastlog').readlines()
|
|
# for i in range(len(lastlog)):
|
|
# print(lastlog[i])
|
|
# lastlog_list.append(lastlog[i])
|
|
# print(lastlog_list)
|
|
print(lastlog) |