python获取本机mac地址和ip地址的方法
更新时间:2015年04月29日 17:07:26 作者:重负在身
这篇文章主要介绍了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程序设计有所帮助。
相关文章
Python报错ModuleNotFoundError: No module named&
在尝试导入TensorBoard模块时,你可能会遇到ModuleNotFoundError: No module named 'tensorboard'的错误,下面我们来分析这个问题并提供解决方案,需要的朋友可以参考下2024-09-09
Python tkinter之Bind(绑定事件)的使用示例
这篇文章主要介绍了Python tkinter之Bind(绑定事件)的使用详解,帮助大家更好的理解和学习python的gui开发,感兴趣的朋友可以了解下2021-02-02


最新评论