Commit 866d9caf authored by Jondy Zhao's avatar Jondy Zhao

use ipwin to count ipv6 route after windows vista.

Fix issue: count ipv6 route failed in non-english environments
parent 7df99eeb
...@@ -313,36 +313,21 @@ class TunnelManager(object): ...@@ -313,36 +313,21 @@ class TunnelManager(object):
if sys.platform == 'cygwin': if sys.platform == 'cygwin':
def _iterRoutes(self): def _iterRoutes(self):
interface_dict = {}
interfaces = subprocess.check_output(
('netsh', 'interface', 'ipv6', 'show', 'interface'),
stderr=subprocess.STDOUT)
for line in interfaces.splitlines():
if not line == '':
fs = line.split(None, 4)
if fs[0].isdigit():
interface_dict[fs[0].strip()] = fs[4].strip()
routing_table = subprocess.check_output(
('netsh', 'interface', 'ipv6', 'show', 'route', 'verbose'),
stderr=subprocess.STDOUT)
# Before Vista # Before Vista
if platform.system()[10:11] == '5': if platform.system()[10:11] == '5':
pname = 'Prefix' args = ('netsh', 'interface', 'ipv6', 'show', 'route', 'verbose')
ifname = lambda a : a
# From Vista later
else: else:
pname = 'Destination Prefix' args = ('ipwin', 'ipv6', 'show', 'route', 'verbose')
ifname = interface_dict.get routing_table = subprocess.check_output(args, stderr=subprocess.STDOUT)
for line in routing_table.splitlines(): for line in routing_table.splitlines():
fs = line.split(':', 1) fs = line.split(':', 1)
test = fs[0].startswith test = fs[0].startswith
if test(pname): if test('Prefix'):
prefix, prefix_len = fs[1].split('/', 1) prefix, prefix_len = fs[1].split('/', 1)
elif test('Interface'): elif test('Interface'):
yield (ifname(fs[1].strip()), yield (fs[1].strip(),
utils.binFromIp(prefix.strip()), utils.binFromIp(prefix.strip()),
int(prefix_len)) int(prefix_len))
else: else:
def _iterRoutes(self): def _iterRoutes(self):
with open('/proc/net/ipv6_route') as f: with open('/proc/net/ipv6_route') as f:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment