首页 > 编程语言 > 详细

Python Network Programming -Gethostname&ip_address

时间:2015-12-21 16:04:20      阅读:156      评论:0      收藏:0      [点我收藏+]
#!/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]

Python Network Programming -Gethostname&ip_address

原文:http://www.cnblogs.com/magicpower/p/5063309.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!