Home >Backend Development >Python Tutorial >python获取本机mac地址和ip地址的方法

python获取本机mac地址和ip地址的方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 11:14:531710browse

本文实例讲述了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程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn