python获取本机mac地址和ip地址的方法
2015-05-04来源:易贤网

这篇文章主要介绍了python获取本机mac地址和ip地址的方法,涉及Python获取系统相关信息的技巧,需要的朋友可以参考下

本文实例讲述了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

希望本文所述对大家的Python程序设计有所帮助。

更多信息请查看IT技术专栏

2026公务员·事业单位培训课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息