Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python interface to view/modify IP routing rules

I'm trying to find a Pythonic interface to what the ip route-style commands do on Linux, similar to how python-iptables is a nice Pythonic interface to iptables which directly calls the C library functions, rather than using subprocess to call and parse the output of running /usr/sbin/iptables. Does such a module exist?

If not, what would be the best way (preferably not involving subprocess-parsing) to do the following in Python:

  • Get the machine's IP routing table
  • Add a new rule to the IP routing table
  • Delete a rule from the IP routing table?
like image 809
Etienne Perot Avatar asked Apr 24 '13 01:04

Etienne Perot


People also ask

Which command can be used to modify the Tcpip routing table?

The Change TCP/IP Route (CHGTCPRTE) command is used to change an existing route in the Transmission Control Protocol/Internet Protocol (TCP/IP) configuration.

What command will display all IP routing protocol?

Use the show ip route EXEC command to display the current state of the routing table.

What is Rt_tables?

The /etc/iproute2/rt_tables file basically allows you to give meaningful names to the route tables. You can reference all the possible tables using just a number, but it is easier to remember and use them if you have a good name.


1 Answers

Did you try pyroute2? Pyroute2 is a pure Python netlink and Linux network configuration library. It requires only Python standard modules and no other 3rd party libraries. Later it can change, but the dependency tree will remain as simple as possible.

like image 146
accdias Avatar answered Sep 28 '22 01:09

accdias