I am attempting on Python 2.6.6 to get the routing table of a system (for a interface) into a python list to parse; but I cannot seem to solve why the entire result is stored into one variable.
The loop seems to iterate over one characters at a time, while the behavior I wanted was one line at a time.
what I get is one character; short example below...
1
0
.
2
4
3
what I'd like line to return; so I can run other commands against each line..
10.243.186.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
10.243.188.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
10.243.184.0 10.243.186.1 255.255.255.128 UG 0 0 0 eth0
Here is the code below...
def getnet(int):
int = 'eth0' ####### for testing only
cmd = ('route -n | grep ' + int)
routes = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE)
routes, err = routes.communicate()
for line in routes:
print line