Get 'ifconfig' information via Python

M.-A. Lemburg mal at
Fri Aug 6 11:08:32 CEST 1999

Ivan Van Laningham wrote:
> > The fcntl.ioctl() function can take a string or an integer as
> > third argument.
> [snip]
> >
> > Building these structs can be done using the Python struct
> > module... playing around with this can probably crash your system
> > though.
> >
> > In the end, I think you're better off hacking together a
> > new extension module.
> >
> Why on earth would reading this information into a struct crash his
> system?  Or am I missing something here?  At worst, writing a messed-up
> struct might hose his ethernet connection, but I really doubt that he
> would be any more likely to crash his system using Python than C.

The ioctl() gives you access to very low-level structures of
the whole system, not only the ethernet devices. Started as root
(which he would have to do to set the ethernet hardware address),
such a script could do plenty of damage in all kinds of weird areas
that are accessible to ioctl().

In David's case only his ethernet device would go wild, I guess.
I still think that accessing the data via an extension is safer
-- at least the module won't work on platforms that the extension
was not compiled for. The Python version will run on all platforms
having fcntl.ioctl() and it is likely that the device struct
layout changes from platform to platform.

Marc-Andre Lemburg
Y2000:                                                   147 days left
Python Pages:                 

More information about the Python-list mailing list