Get 'ifconfig' information via Python

M.-A. Lemburg mal at
Wed Aug 4 06:38:54 EDT 1999

M.-A. Lemburg wrote:
> David N. Welton wrote:
> >
> > So, I think I'm getting close...
> >
> > import fcntl
> > import IN
> > import struct
> >
> > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> >
> > res = fcntl.ioctl(s, IN.SIOCSIFHWADDR, ??????)

And one more thing: the first argument must be the file handle,
i.e. s.fileno() in this case.

Setting the hardware address is only allowed for super users,

>>> fcntl.ioctl(s.fileno(), IN.SIOCSIFHWADDR, '')
Traceback (innermost last):
  File "<stdin>", line 1, in ?
IOError: (1, 'Operation not permitted')


Would be nice to have an output interface for ioctl() too. That
way we could access many interesting technical details
about the system running the program. This should be easy to
implement: instead of returning just the return code integer,
the function could return a tuple (RC, buffer) and then leave
the parsing of the buffer to the user.

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

More information about the Python-list mailing list