31 lines
654 B
Python
31 lines
654 B
Python
# _*_ coding: utf-8 _*_
|
|
# @Time :2022/5/26 09:33
|
|
# @Email :508737091@qq.com
|
|
# @Author :qiangyanwen
|
|
# @File :system.py
|
|
import socket
|
|
import sys
|
|
|
|
|
|
def get_host_ip() -> str:
|
|
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
try:
|
|
client.connect(('8.8.8.8', 80))
|
|
ip = client.getsockname()[0]
|
|
except ConnectionError as connect:
|
|
raise ConnectionError("socket 连接异常请检查 detail: %s" % connect)
|
|
finally:
|
|
client.close()
|
|
return ip
|
|
|
|
|
|
def current_platform() -> str:
|
|
return sys.platform
|
|
|
|
|
|
system = current_platform()
|
|
host = get_host_ip()
|
|
print(host)
|
|
|
|
__all__ = ["system", "host"]
|