Skip to content
Snippets Groups Projects
Commit 1f926c28 authored by Dirk Loss's avatar Dirk Loss
Browse files

Improved regex for routing table parsing on Windows

The former regex for the gateway did not include the '-' character,
so it did not work on English Vista/Win7 systems where the gateway
is shown as "On-link". We now allow any text in the gateway column.
parent 15145f5a
No related branches found
No related tags found
No related merge requests found
...@@ -226,11 +226,13 @@ pcapdnet.open_pcap = lambda iface,*args,**kargs: _orig_open_pcap(pcap_name(iface ...@@ -226,11 +226,13 @@ pcapdnet.open_pcap = lambda iface,*args,**kargs: _orig_open_pcap(pcap_name(iface
def read_routes(): def read_routes():
ok = 0 ok = 0
routes = [] routes = []
ip = '(\d+\.\d+\.\d+\.\d+)\s+' ip = '(\d+\.\d+\.\d+\.\d+)'
# On Vista and Windows 7 the gateway can be IP or 'on-link'. # On Vista and Windows 7 the gateway can be IP or 'On-link'.
# The exact 'on-link' string depends on the locale. # But the exact 'On-link' string depends on the locale, so we allow any text.
gw_pattern = '([\w\s]+|\d+\.\d+\.\d+\.\d+)\s+' gw_pattern = '(.+)'
netstat_line = ip + ip + gw_pattern + ip + "(\d+)" metric_pattern = "(\d+)"
delim = "\s+" # The columns are separated by whitespace
netstat_line = delim.join([ip, ip, gw_pattern, ip, metric_pattern])
pattern = re.compile(netstat_line) pattern = re.compile(netstat_line)
f=os.popen("netstat -rn") f=os.popen("netstat -rn")
for l in f.readlines(): for l in f.readlines():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment