Skip to content
This repository has been archived by the owner on Apr 15, 2021. It is now read-only.

fetching information about ip routes #1

Open
abbbe opened this issue May 8, 2012 · 4 comments
Open

fetching information about ip routes #1

abbbe opened this issue May 8, 2012 · 4 comments

Comments

@abbbe
Copy link

abbbe commented May 8, 2012

Hello,

Do you already have a feature to fetch information about IP routes? Can't seem to find it. I don't mind implementing it myself. Do you happen to have a sample piece of code I can use as a base?

Regards,
Alex

@pmuller
Copy link
Owner

pmuller commented May 9, 2012

Hi !

It's not currently implemented, but it's really easy to add it.

The code looks for parsers of /proc files in procfs.proc.* and parsers of /proc/ files in procfs.processes.*.
If no parser is found, access to that file from procfs (for example proc.net.route) returns the raw file content as a string.

To write a parser, you just have to add a route class in procfs/processes/net/__init__.py which inherits from the ProcessFile class with a _parse method :

class route(ProcessFile):
    def _parse(self, data):
        # data is a string read from the file.
        # parse it and return a python object

Tell me if you need more information. And thank you for your interest. :-)

pmuller pushed a commit that referenced this issue Jul 29, 2014
Modify not to use eval()
@q1208c
Copy link

q1208c commented Jun 18, 2015

Hi,
Procfs is very nice tool for me, I use it to get more information for the system.
Few days ago, I try to find the routing table, and I try to use procfs.Proc.net.route.
But, I found a litter different from "ip route show" and the "procfs.Proc.net.route()".
The "ip route show" will show the duplicates, but the procfs use Dict, so, no duplicates returned.
for normal proc record, the Dict is better, but for route, sometimes, we need the duplicates records.

How i can do for this ?

sorry for my poor English. :(

@perryjrandall
Copy link

You can make the route item optionally a list instead of a string if you dont want to break compatibility with existing code, or you can add another class like routelist which has a list of the routes instead of a dictionary.

@q1208c
Copy link

q1208c commented Jul 15, 2015

thanks. I try it later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants