import PySimpleGUI as sg
import socket
import getpass
import platform
systerm_sy=platform.system() #系统信息
systerm_version=platform.version()#系统版本
user_name=getpass.getuser()#获取当前用户
host_name=socket.gethostname()#获取机刷几名称
# 设计界面函数
def ui_w():
sg.theme('DarkGreen5')
layout = [
[sg.T(" "*5),sg.T("计算机基本信息",text_color=sg.YELLOWS[0]),sg.T(" "*5)],
[sg.T("IP地址:"),sg.T(get_host_ip())],
[sg.T("操作系统:"), sg.T(systerm_sy)],
[sg.T("当前用户:"),sg.T(user_name)],
]
window = sg.Window('IP查询工具', layout, font=("Helvetica", 18,),icon='ff.ico')
while True:
event, value = window.read()
if event in (None,"e"):
break
window.close()
# 获取Ip函数
def get_host_ip():
"""
查询本机ip地址
return: ip
"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
if __name__ == '__main__':
print(get_host_ip())
print(user_name)
print(host_name)
print(systerm_sy)
print(systerm_version)
ui_w()