工具环境
python 3.7.3
windows环境
查询本机用户名
image.pngimport socket
hostname = socket.gethostname()
print(hostname)
查询本机IP
image.pngimport socket
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
print(ip)
整合
import socket
hostname = socket.gethostname()
print(hostname)
ip = socket.gethostbyname(hostname)
print(ip)
网友评论