import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
hostname = socket.gethostname()  # 获取电脑名称  gethostbyname 参数为一个域名,返回一个指向hostent 的指针
ip=socket.gethostbyname(hostname) # 获取电脑ip
print("我的主机名字为{},主机ip为{}".format(hostname,ip))

# 打印:我的主机名字为The,主机ip为192.168.2.1

 

相关文章:

  • 2021-06-28
  • 2022-02-13
  • 2022-01-16
  • 2021-11-27
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
猜你喜欢
  • 2022-02-16
  • 2021-11-20
  • 2021-06-04
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案