Exemple #1
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()
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_output = iosvl2.facts
print(json.dumps(ios_output, indent=4))

iosvl2.config_list(['hostname R100'])
Exemple #3
0
import json
from pyntc import ntc_device as NTC
iosvl2 = NTC(host='192.168.122.226',
             username='******',
             password='******',
             device_type='cisco_ios_ssh')
iosvl2.open()

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

iosvl2.config_list([
    'hostname S1', 'router ospf 1', 'network 0.0.0.0 255.255.255.255 area 0',
    'network 192.168.122.0 0.0.0.255 area 0',
    'network 10.1.20.0 0.0.0.255 area 1'
])

iosvl2.close()
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'])

print(router6.show('show run | in hostname'))
print(router6.show('show run interface loop 111'))
router6.save()


router6.backup_running_config('Router6.cfg')

router6.close()

Exemple #5
0
import json
from pyntc import ntc_device as NTC

#Define parameters to establish SSH session
iosvl2 = NTC(host='192.168.122.2',
             username='******',
             password='******',
             device_type='cisco_ios_ssh')

#Open SSH session
iosvl2.open()

#Gather uptime, interfaces etc. from device
ios_output = iosvl2.facts
#Utilise json to format output to more readable format
print(json.dumps(ios_output, indent=4))

#Apply configuration commands in list
iosvl2.config_list(['hostname s1_python'])
iosvl2.close()
#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 #7
0
import json
from pyntc import ntc_device as NTC
iosvl2 = NTC(host="192.168.122.82",
             username="******",
             password="******",
             device_type="cisco_ios_ssh")
iosvl2.open()

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

iosvl2.config_list([
    "hostname s1", "router ospf 1",
    "no network 0.0.0.0 255.255.255.255 area 0",
    "network 10.1.1.0 0.0.0.255 area 0", "network 10.1.2.0 0.0.0.255 area 1"
])
#!/usr/bin/env python

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(['router ospf 1', 
                 'no network 0.0.0.0 255.255.255.255 area 0', 
                 'network 10.2.2.1 255.255.255.255 area 0', 
                 'network 192.168.122.0 255.255.255.0 area 0',
                 'network 10.3.3.1 255.255.255.255 area 0'])
                 
rtr.close()
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_output = iosvl2.facts
print(json.dumps(ios_output, indent=4))

iosvl2.config_list([
    'hostname R100', 'router ospf 100', 'network 192.168.1.0 0.0.0.255 area 0'
])
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()
Exemple #11
0
#
import json
from pyntc import ntc_device as NTC

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

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

#iosvl2.config_list(['hostname s1_python', 'router ospf 1', 'network 0.0.0.0 255.255.255.255 area 0'])

iosvl2.config_list([
    'hostname s1', 'router ospf 1',
    'no network 0.0.0.0 255.255.255.255 area 0',
    'network 192.168.x.0 0.0.0.255 area 0', 'network 10.1.x.x 0.0.0.255 area 1'
])

iosvl2.close()
Exemple #12
0
#/python3

import scapy

import json
from pyntc import ntc_device as NTC

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

# print(json.dumps(SW.facts, indent=4))

SW.config('hostname SWITCH1')
SW.config_list(['int lo3', 'ip add 4.4.4.4 255.255.255.255'])
SW.close()