python獲取本機(jī)mac地址和ip地址的方法

字號(hào):


    這篇文章主要介紹了python獲取本機(jī)mac地址和ip地址的方法,涉及Python獲取系統(tǒng)相關(guān)信息的技巧,需要的朋友可以參考下
    本文實(shí)例講述了python獲取本機(jī)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
    希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。