Get 'ifconfig' information via Python

M.-A. Lemburg mal at lemburg.com
Wed Aug 4 12:38:54 CEST 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,
BTW:

>>> 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
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





More information about the Python-list mailing list