From 1f926c285c09c1d831540fc9516ddaf5a7994602 Mon Sep 17 00:00:00 2001 From: Dirk Loss <mail@dirk-loss.de> Date: Sun, 18 Oct 2009 17:48:13 +0200 Subject: [PATCH] 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. --- scapy/arch/windows/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) mode change 100644 => 100755 scapy/arch/windows/__init__.py diff --git a/scapy/arch/windows/__init__.py b/scapy/arch/windows/__init__.py old mode 100644 new mode 100755 index 6b55b978..a80cbce3 --- a/scapy/arch/windows/__init__.py +++ b/scapy/arch/windows/__init__.py @@ -226,11 +226,13 @@ pcapdnet.open_pcap = lambda iface,*args,**kargs: _orig_open_pcap(pcap_name(iface def read_routes(): ok = 0 routes = [] - ip = '(\d+\.\d+\.\d+\.\d+)\s+' - # On Vista and Windows 7 the gateway can be IP or 'on-link'. - # The exact 'on-link' string depends on the locale. - gw_pattern = '([\w\s]+|\d+\.\d+\.\d+\.\d+)\s+' - netstat_line = ip + ip + gw_pattern + ip + "(\d+)" + ip = '(\d+\.\d+\.\d+\.\d+)' + # On Vista and Windows 7 the gateway can be IP or 'On-link'. + # But the exact 'On-link' string depends on the locale, so we allow any text. + gw_pattern = '(.+)' + 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) f=os.popen("netstat -rn") for l in f.readlines(): -- GitLab