python獲取本機mac地址和ip地址的方法
更新時間:2015年04月29日 17:07:26 作者:重負在身
這篇文章主要介紹了python獲取本機mac地址和ip地址的方法,涉及Python獲取系統(tǒng)相關信息的技巧,需要的朋友可以參考下
本文實例講述了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使用ffmpy將amr格式的音頻轉化為mp3格式的例子
今天小編就為大家分享一篇Python使用ffmpy將amr格式的音頻轉化為mp3格式的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08Python程序打包工具py2exe和PyInstaller詳解
這篇文章主要介紹了Python程序打包工具py2exe和PyInstaller詳解,如果可以提前將程序打包成 Windows平臺的 .exe 文件或者是Linux下的 .sh 腳本,那么使用起來就會方便很多,需要的朋友可以參考下2019-06-06