python獲取設備主機名和IP地址

import socket


def print_machine_info():
    host_name = socket.gethostname()
    ip_address = socket.gethostbyname(host_name)
    print("Host name: %s" % host_name)
    print("IP address: %s" % ip_address)
    hostname = socket.gethostbyaddr('192.168.201.227')
    print(hostname)


def print_device_remote_info():
      host_name = 'swissmic.cn'
      print(" Host name: %s" % host_name)
      print(" IP address: %s" % socket.gethostbyname(host_name))
相關文章
相關標籤/搜索