python2.7_1.2_打印设备名和IPv4地址

代码如下:

# -*- coding: utf-8 -*-
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

if __name__ == '__main__':
    print_machine_info()

 

你可能感兴趣的:(python2.7_1.2_打印设备名和IPv4地址)