From 5f02475eb7ad33c4a17f484f283a9e64d705a59a 2013-11-15 01:30:40 From: MinRK Date: 2013-11-15 01:30:40 Subject: [PATCH] relax ipconfig matching on Windows looser match via regular expression, doesn't make English assumptions. --- diff --git a/IPython/utils/localinterfaces.py b/IPython/utils/localinterfaces.py index 184d254..428623f 100644 --- a/IPython/utils/localinterfaces.py +++ b/IPython/utils/localinterfaces.py @@ -23,6 +23,7 @@ PUBLIC_IPS : A list of public IP addresses that point to this machine. #----------------------------------------------------------------------------- import os +import re import socket from .data import uniq_stable @@ -118,6 +119,7 @@ def _load_ips_ip(): addrs.append(blocks[1].split('/')[0]) _populate_from_list(addrs) +_ipconfig_ipv4_pat = re.compile(r'ipv4.*(\d+\.\d+\.\d+\.\d+)$', re.IGNORECASE) def _load_ips_ipconfig(): """load ip addresses from `ipconfig` output (Windows)""" @@ -128,9 +130,9 @@ def _load_ips_ipconfig(): lines = out.splitlines() addrs = ['127.0.0.1'] for line in lines: - line = line.lower().split() - if line[:2] == ['ipv4', 'address']: - addrs.append(line.split()[-1]) + m = _ipconfig_ipv4_pat.match(line.strip()) + if m: + addrs.append(m.group(1)) _populate_from_list(addrs)