[英]How to get the host's IP address using python?
I'm trying to get a host's ip address using this code:我正在尝试使用以下代码获取主机的 IP 地址:
import os
import socket
ip = socket.gethostbyname(os.environ['COMPUTERNAME'])
the problem is that this host has VMware installed and the IP I get with the code above is that belonging to VMware, and not to the host.问题是这台主机安装了VMware,我用上面的代码得到的IP是属于VMware的,而不是主机的。 How can I fix this without uninstalling VMware?如何在不卸载 VMware 的情况下解决此问题? :P :P
如果您使用的是 Windows,则可以进行此操作
iphost = socket.gethostbyname(socket.gethostname())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.