Adds a get_route() function to win_network.py

Returns the same data as the get_route() function in the network.py
execution module.
This commit is contained in:
Loren Gordon 2017-05-05 14:07:58 -04:00
parent 7d900d31ea
commit b9cbbc0290

View File

@ -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<source>[\d\.:]+)?.*"
r"^InterfaceAlias\s+:\s(?P<interface>[\w\.\:\-\ ]+)?.*"
r"^NextHop\s+:\s(?P<gateway>[\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