3

How can I do the following things in python:

  1. List all the IP interfaces on the current machine.
  2. Receive updates about changes in network interfaces (goes up, goes down, changes IP address).

Any python package available in Ubuntu Hardy will do.

3 Answers 3

3

I think the best way to do this is via dbus-python.

The tutorial touches on network interfaces a little bit:

import dbus
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.NetworkManager',
                       '/org/freedesktop/NetworkManager/Devices/eth0')
# proxy is a dbus.proxies.ProxyObject
Sign up to request clarification or add additional context in comments.

Comments

0

I have been using the following code,

temp =  str(os.system("ifconfig -a | awk '$2~/^Link/{_1=$1;getline;if($2~/^addr/){print _1" "}}'"))

it will give the 'up' network interfaces

e.g. eth0, eth2, wlan0

Comments

0

No, no... You don't need to bother os.system() or dbus API.

What you really need is to use netlink API to implement this. Either use libnl interface (netlink.route.link) or handle netlink messages by yourself. Take a look at this example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.