diff --git a/salt/modules/win_network.py b/salt/modules/win_network.py index 1c11635cb6..e940271604 100644 --- a/salt/modules/win_network.py +++ b/salt/modules/win_network.py @@ -4,6 +4,8 @@ Module for gathering and managing network information ''' from __future__ import absolute_import +import re + # Import salt libs import salt.utils import hashlib @@ -197,6 +199,35 @@ def nslookup(host): return ret +def get_route(ip): + ''' + Return routing information for given destination ip + + .. versionadded:: 2016.11.6 + + CLI Example:: + + salt '*' network.get_route 10.10.10.10 + ''' + cmd = 'Find-NetRoute -RemoteIPAddress {0}'.format(ip) + out = __salt__['cmd.run'](cmd, shell='powershell', python_shell=True) + regexp = re.compile( + r"^IPAddress\s+:\s(?P[\d\.:]+)?.*" + r"^InterfaceAlias\s+:\s(?P[\w\.\:\-\ ]+)?.*" + r"^NextHop\s+:\s(?P[\d\.:]+)", + flags=re.MULTILINE | re.DOTALL + ) + m = regexp.search(out) + ret = { + 'destination': ip, + 'gateway': m.group('gateway'), + 'interface': m.group('interface'), + 'source': m.group('source') + } + + return ret + + def dig(host): ''' Performs a DNS lookup with dig