get mac/ physical address of network card with python

Skip Montanaro skip at pobox.com
Sun Aug 26 13:30:57 EDT 2001


    Grant> Well, this works under Linux (but I don't think many other
    Grant> systems support raw sockets):

    Grant>   s = socket.socket(socket.AF_PACKET,socket.SOCK_RAW)
    Grant>   s.bind(("eth0",9999))
    Grant>   mac = s.getsockname()[-1]
  
    Grant>   print ":".join(["%02x" % ord(x) for x in mac])

And you have to be root... ;-)

Skip




More information about the Python-list mailing list