import json
from pyntc import ntc_device as NTC

iosvl2 = NTC(host='192.168.1.50',
             username='******',
             password='******',
             device_type='cisco_ios_ssh')
iosvl2.open()

ios_run = iosvl2.running_config
print(ios_run)
import json
from pyntc import ntc_device as NTC

R1 = {
    'host': 'R1',
    'device_type':'cisco_ios_ssh',
    'username': '******',
    'password': '******',
}

switch1 = {
    'host': 'Switch1',
    'device_type': 'cisco_ios_ssh',
    'username': '******',
    'password': '******',
}

all_devices = [R1,switch1]
for devices in all_devices:
    connect = NTC(**devices)
    connect.open()
    output = connect.running_config
    print (json.dumps(output, indent=4))
Exemple #3
0
import json
from pyntc import ntc_device as NTC
site2 = NTC(host='102.1.1.100', username='******', password='******', device_type='cisco_ios_ssh')
site2.open()
site2_output = site2.facts
print (json.dumps(site2_output, indent=4))
site2.config_list(['crypto isakmp policy 1',
                   'authentication pre-share',
                   'encryption aes',
                   'hash sha',
                   'group 5',
                   'lifetime 1800',
                   'exit',
                   'crypto isakmp key shiva address 101.1.1.100',
                   'crypto ipsec transform-set t-set esp-aes esp-sha-hmac',
                   'mode tunnel',
                   'exit',
                   'crypto ipsec security-association lifetime seconds 1800',
                   'access-list 101 permit ip 192.168.102.0 0.0.0.255 192.168.122.0 0.0.0.255', 
                   'crypto map test 10 ipsec-isakmp',
                   'set transform-set t-set',
                   'set peer 101.1.1.100',
                   'match address 101',
                   'int g0/0',
                   'crypto map test',
                   'ip access-list extended natacl',
                   '1 deny ip 192.168.102.0 0.0.0.255 192.168.122.0 0.0.0.255',
                   'exit'])
site2.close()
# https://github.com/networktocode/pyntc
# this is amazing
import json
from pyntc import ntc_device as NTC


router6 = NTC(host='192.168.122.60',username='******',password='******',device_type='cisco_ios_ssh')

router6.open()

print(json.dumps(router6.facts,indent=2))



print(router6.show('show ip arp'))

print(router6.show_list(['show ip inte bri','sho clock','show ip arp']))


print(router6.running_config)







router6.config('hostname test-Router6')
router6.config_list(['interface loop 111','ip address 111.11.11.11 255.255.255.255','description test loopback','no shut'])
Exemple #5
0
from pyntc import ntc_device as NTC

iosvl3 = NTC(host='172.31.33.201',
             username='******',
             password='******',
             device_type='cisco_ios_ssh')
iosvl3.open()

iosvl3.config_list['hostname Router1', 'router ospf 1',
                   'network 10.0.0.0 255.255.255.0 area 0.0.0.0']
Exemple #6
0
import json
from pyntc import ntc_device as NTC
site1 = NTC(host='192.168.122.56',
            username='******',
            password='******',
            device_type='cisco_ios_ssh')
site1.open()
site1_output = site1.facts
print(json.dumps(site1_output, indent=4))
site1.config_list([
    'crypto isakmp policy 1', 'authentication pre-share', 'encryption aes',
    'hash sha', 'group 5', 'lifetime 1800', 'exit',
    'crypto isakmp key shiva address 102.1.1.100',
    'crypto ipsec transform-set t-set esp-aes esp-sha-hmac', 'mode tunnel',
    'exit', 'crypto ipsec security-association lifetime seconds 1800',
    'access-list 101 permit ip 192.168.122.0 0.0.0.255 192.168.102.0 0.0.0.255',
    'crypto map test 10 ipsec-isakmp', 'set transform-set t-set',
    'set peer 102.1.1.100', 'match address 101', 'int g0/0', 'crypto map test',
    'ip access-list extended natacl',
    '1 deny ip 192.168.122.0 0.0.0.255 192.168.102.0 0.0.0.255', 'exit'
])
site1.close()
import os
import json
from pyntc import ntc_device as NTC

IP_LIST = [
    "192.168.44.110", "192.168.44.111", "192.168.44.121", "192.168.44.122"
]
# IP_LIST = ["192.168.44.110"]

for IP in IP_LIST:

    DEVICE = NTC(host=str(IP),
                 username='******',
                 password='******',
                 device_type='cisco_ios_ssh')
    DEVICE.open()

    print("Connected to " + str(IP))

    # ------------------------------------
    print("Facts - " + str(IP))
    OUTPUT = DEVICE.facts
    OUTPUT = json.dumps(OUTPUT, indent=4)
    print(OUTPUT)

    # ------------------------------------
    print("Running Config - " + str(IP))
    OUTPUT = DEVICE.running_config
    print(OUTPUT)

    # ------------------------------------
Exemple #8
0
    print('No changes required.')
    iosv_l2.discard_config()


########################################################################################################################
### pyntc
########################################################################################################################

pip install pyntc

##
import json
from pyntc import ntc_device as NTC

iosv_l2 = NTC(host='192.168.1.1', username='******', password='******',device_type='cisco_ios_ssh')
iosv_l2.open()
ios_output = iosvl2.facts
print(json.dumps(ios_output, ident=4))
iosvl2.config_list(['hostname cisco_test'])
ios_output = iosvl2.running_config

# бэкап
ios_output = iosvl2.backup_running_config







#pyntc is an open source multi-vendor Python library that establishes a common framework for working with different network APIs & device types (including IOS devices)
#
#It's main purpose to is to simplify the execution of common tasks including:
#
#Executing commands
#Copying files
#Upgrading devices
#Rebooting devices
#Saving / Backing Up Configs
#pyntc currently supports four device types:
#
#cisco_ios_ssh
#cisco_nxos_nxapi
#arista_eos_eapi
#juniper_junos_netconf
#https://github.com/networktocode/pyntc

import json
from pyntc import ntc_device as NTC
rtr = NTC(host='192.168.122.26',
          username='******',
          password='******',
          device_type='cisco_ios_ssh')
rtr.open()

ios_output = rtr.facts
print(json.dumps(ios_output, indent=4))

rtr.config_list([' hostname mgmt_python'])
Exemple #10
0
import json
from pyntc import ntc_device as NTC

SW = NTC(host='192.168.2.11',
         username='******',
         password='******',
         device_type='cisco_ios_ssh')
SW.open()

#print (json.dumps(SW.facts, indent=4))
SW.config('hostname pyntc_S1')
SW.config_list(['router ospf 1', 'network 192.168.2.0 0.0.0.255 area 0'])

SW.close()