Search code examples
pythonlinuxsubprocessifconfigiwconfig

Python and accessing command line utilities ifconfig, iwconfig and iw directly


I'm accessing ifconfig, iwconfig and iw from subprocess.Popen as below:

p = sp.Popen(["ifconfig",nic],stdin=sp.PIPE,stdout=sp.PIPE,stderr=sp.PIPE)
out,err = p.communicate()

Is there a better way, i.e faster to do this such as interfacing directly to the underlying code perhaps or is the added time delay negligible - time becomes a concern when using iw to switch channels.


Solution

  • So, finally got around to writing own code - interfaces directly with netlink and ioctl to handle iw and ifconfig respectively - hosted on https://github.com/wraith-wireless/pyric and https://pypi.python.org/pypi/PyRIC/