当前位置:首页 > 操作系统 > MacOs

python获取本机mac地址和ip地址列表的代码

把写内容过程中常用的一些内容段记录起来,如下内容段是关于python获取本机mac地址和ip地址列表的内容。

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







【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐