7

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?
2
  • 1
    You probably don't want to hear this, but I think you're better off parsing the output of shell commands. The routines controlling all this behind those shell commands are probably not very portable. Keep in mind: Parsing the output of shell commands is an utter mess on Windows, but on *ix, it really works quite well. Commented Apr 24, 2013 at 3:11
  • @dstromberg I suppose that's the way it'll have to be Commented Apr 24, 2013 at 3:20

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

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.