import socket
hostname = socket.gethostname() ## 获取主机名
ip_address = socket.gethostbyname(hostname) # 通过主机名获取 IP 地址
print(“服务器主机 IP 地址为:”, ip_address)
python 查看服务器主机 IP 地址
最新推荐文章于 2024-11-18 17:48:52 发布
import socket
hostname = socket.gethostname() ## 获取主机名
ip_address = socket.gethostbyname(hostname) # 通过主机名获取 IP 地址
print(“服务器主机 IP 地址为:”, ip_address)