python查询本机用户名及本机IP

工具环境

python 3.7.3
windows环境

查询本机用户名

image.png
import  socket
hostname = socket.gethostname()
print(hostname)

查询本机IP

image.png
import  socket
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
print(ip)

整合

import  socket
hostname = socket.gethostname()
print(hostname)
ip = socket.gethostbyname(hostname)
print(ip)

你可能感兴趣的:(python查询本机用户名及本机IP)