本文實例講述了python獲取本機mac地址和ip地址的方法。分享給大家供大家參考。具體如下:
import sys, socketdef getipaddrs(hostname): result = socket.getaddrinfo(hostname,None,0,socket.SOCK_STREAM) return [x[4][0] for x in result]# the name of the local machinehostname = socket.gethostname()try: print "IP addresses:", ", ".join(getipaddrs(hostname))except socket.gaierror, e: print "Couldn't not get IP addresses:", e
希望本文所述對大家的Python程序設計有所幫助。
新聞熱點
疑難解答