get mac/ physical address of network card with python
Grant Edwards
grante at visi.com
Sun Aug 26 12:52:05 EDT 2001
On Sun, 26 Aug 2001 11:06:14 -0400, Scott Syms <Scott.Syms at pwgsc.gc.ca> wrote:
>Wondering if anyone knew how to grab the mac address of a network card from
>within Python.
Well, this works under Linux (but I don't think many other
systems support raw sockets):
s = socket.socket(socket.AF_PACKET,socket.SOCK_RAW)
s.bind(("eth0",9999))
mac = s.getsockname()[-1]
print ":".join(["%02x" % ord(x) for x in mac])
--
Grant Edwards grante Yow! It's NO USE... I've
at gone to "CLUB MED"!!
visi.com
More information about the Python-list
mailing list