python获取本机mac地址和ip地址的方法
更新时间:2015年04月29日 17:07:26 作者:重负在身
这篇文章主要介绍了python获取本机mac地址和ip地址的方法,涉及Python获取系统相关信息的技巧,需要的朋友可以参考下
本文实例讲述了python获取本机mac地址和ip地址的方法。分享给大家供大家参考。具体如下:
1 2 3 4 5 6 7 8 9 10 | import sys, socket def getipaddrs(hostname): result = socket.getaddrinfo(hostname, None , 0 ,socket.SOCK_STREAM) return [x[ 4 ][ 0 ] for x in result] # the name of the local machine hostname = socket.gethostname() try : print "IP addresses:" , ", " .join(getipaddrs(hostname)) except socket.gaierror, e: print "Couldn't not get IP addresses:" , e |
希望本文所述对大家的Python程序设计有所帮助。
您可能感兴趣的文章:

微信公众号搜索 “ 脚本之家 ” ,选择关注
程序猿的那些事、送书等活动等着你
最新评论