1.快速查看主机名和对应的IP地址小程序

 1 import socket
 2 
 3 
 4 def print_machine_info():  # 定义print_machine_info()类
 5     host_name = socket.gethostname()  # 获取主机名
 6     ip_address = socket.gethostbyname(host_name)  # 获取主机名对应的IP地址
 7     print("Host name: %s" % host_name)  # 打印主机名
 8     print("IP address: %s" % ip_address)  # 打印主机名对应的IP地址
 9 
10 
11 if __name__ == '__main__':
12     print_machine_info()
13     # 在命令行中调用这个模块,print_machine_info()函数会自动运行
14     # 如果从其他脚本中导入,需要用户手动调用这个函数

2.关于gethostname()和gethostbyname()解释

def gethostname():  # real signature unknown; restored from __doc__
    """
    gethostname() -> string

    Return the current host name.
    """
    return


def gethostbyname(host):  # real signature unknown; restored from __doc__
    """
    gethostbyname(host) -> address

    Return the IP address (a string of the form '255.255.255.255') for a host.
    """
    pass

 

相关文章:

  • 2022-02-26
  • 2022-12-23
  • 2021-07-11
  • 2022-01-08
  • 2021-06-17
  • 2022-02-12
  • 2021-09-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-03-31
  • 2021-04-13
  • 2021-12-26
  • 2021-11-19
相关资源
相似解决方案