python获取本机mac地址和ip地址的方法
时间:2021-01-22 12:29:03|栏目: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程序设计有所帮助。
上一篇:Python IDE环境之 新版Pycharm安装详细教程
栏 目:Python代码
下一篇:Python中工作日类库Busines Holiday的介绍与使用
本文地址:http://www.codeinn.net/misctech/49512.html






