php版本
$ip = gethostbyname('www.baidu.com');
echo $ip;
?>
python版本
import socket
ip = socket.gethostbyname('www.baidu.com')
import socket
# 查询本机ip地址
def get_host_ip():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip