__MagicPower
Do one thing and do it best!

导航

 
#!/usr/bin/env python
#python network programming cookbook -- chapter -1
#this program is optimized for Python 2.7 it may run on any
#other python version with/without modifications

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()

Test:

Host name:kevins-MacBook-Pro.local
IP address:192.168.0.100
[Finished in 0.4s]

posted on 2015-12-21 14:18  __MagicPower  阅读(191)  评论(0编辑  收藏  举报