"""Seperates the interface input from the user into the name and number ex.
    Gi1/0/1 becomes ('Gi', '1/0/1') or GigabitEthernet1/0/1 becomes ('GigabitEthernet', '1/0/1')"""
    interface_name = ''
    interface_number = ''
    x = 0
    for letter in input:
        if letter.isdigit():
            interface_number = input[x:]
            break
        else:
            interface_name += letter
        x += 1
    return interface_name.strip(' '), interface_number.strip(' ')


app = base.CLIApp()
app.add_argument(
    'interface',
    help=
    'Interface to view the configuration of ex. gi1/0/1 or GigabitEthernet1/0/1',
    type=str)
cisco_cfg = app.setUp()

# parses the user input interface argument to be able to search
interface = parse_input(app.parsed_args.interface)

# grabs the interface config and prints it out to the user
interface_config = cisco_cfg.find_all_children(r'^interface.*{}.*{}$'.format(
    interface[0], interface[1]))
for line in interface_config:
    print(line)
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


Script to list the local users on a Cisco device
"""
import os
import sys
script_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(script_path)
import base

t = base.CLIApp(description='Script to list the local users on a Cisco device')
cisco_cfg = t.setUp()

[print(''.join(x.text.split(' ')[1])) for x in cisco_cfg.find_objects(r'^username')]
Пример #3
0
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


This is a skeleton script that will by default accept a config file for a cisco config or accept config from
stdin via a pipeline. To add to this script simply append to the bottom of this file and/or add arguments to the parser section
"""
import os
import sys
script_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(script_path)
import base

t = base.CLIApp()
cisco_cfg = t.setUp()
Пример #4
0
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


This script is designed to emulate the "include" command on Cisco IOS to only print lines containing
the string after
"""
import os
import sys
script_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(script_path)
import base

app = base.CLIApp(
    description='Script to emulate the "include" command on IOS.')
app.add_argument('searchterm',
                 help='Line of configuration to begin printing at')
app.add_argument('-cs',
                 help='Case sensitive search (defaults to case insensitive)',
                 action='store_true')
cisco_cfg = app.setUp_no_cisco_config()

for line in app.raw_config:
    if app.parsed_args.cs:
        search_term = app.parsed_args.searchterm
        target_line = line
    else:
        search_term = app.parsed_args.searchterm.lower()
        target_line = line.lower()
Пример #5
0
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


Script to list the configured vlans on the device
"""
import os
import sys
script_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(script_path)
import base

t = base.CLIApp(description='Script to list the configured vlans on a Cisco device.')
cisco_cfg = t.setUp()

# finds any line in the config that starts with the word 'vlan' and then has a number
# and prints them out
[print(x.text) for x in cisco_cfg.find_objects(r'^vlan \d')]
Пример #6
0
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

This script will list all of the NTP servers configured on the Cisco device
"""
import os
import sys
script_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(script_path)
import base

t = base.CLIApp(description='Lists all interfaces that are not admin down and are missing a description')
cisco_cfg = t.setUp()

for x in cisco_cfg.find_objects(r'^ntp server'):
    print(''.join(x.text.split(' ')[-1:]))
Пример #7
0
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


Script to list the line inputs that are configured to allow telnet
"""

import os
import sys
script_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(script_path)
import base

t = base.CLIApp(
    description=
    'Script to display the line inputs configured to allow Telnet connections.'
)
cisco_cfg = t.setUp()

results = []
[
    results.append(x)
    for x in cisco_cfg.find_objects_w_child(r'[a-z]+', 'input telnet')
]
[
    results.append(x)
    for x in cisco_cfg.find_objects_w_child(r'[a-z]+', 'input all')
]

for x in results:
    print(x.text)