def connect(ne_addr, ne_username, ne_password):

    # check to see if ne_addr is a valid IP(v6) address
    if not (HostIpCheck(ne_addr).is_ipv4() or HostIpCheck(ne_addr).is_ipv6()):
        raise ValueError('%s is not a valid IP address' % ne_addr)

    # TLS Connection (This is the TLS Pinning Handler)
    class PinningHandler(tlspinning.TLSUnverifiedElementHandler):
        def __init__(self, pinning_file):
            self.pinning_file = pinning_file

        def handle_verify(self, host, hashtype, finger_print, changed):
            return tlspinning.DecisionType.ACCEPT_ONCE

    # Connection to my onePK enabled Network Element
    config = SessionConfig(None)
    config.set_tls_pinning('', PinningHandler(''))
    config.transportMode = SessionConfig.SessionTransportMode.TLS
    network_element = NetworkElement(ne_addr)

    # Try authenticating, raise error if unsuccessful
    try:
        network_element.connect(ne_username, ne_password, config)
    except OnepConnectionException:
        raise ValueError('Invalid Credentials or unable to reach %s.' %
                         network_element)

    return network_element
def connect(ne_addr, ne_username, ne_password):

	# check to see if ne_addr is a valid IP(v6) address
	if not (HostIpCheck(ne_addr).is_ipv4() or HostIpCheck(ne_addr).is_ipv6()):
		raise ValueError('%s is not a valid IP address' % ne_addr)	

	# TLS Connection (This is the TLS Pinning Handler)  
	class PinningHandler(tlspinning.TLSUnverifiedElementHandler):  
	   def __init__(self, pinning_file):  
	       self.pinning_file = pinning_file  
	   def handle_verify(self, host, hashtype, finger_print, changed):  
	       return tlspinning.DecisionType.ACCEPT_ONCE  
	  
	# Connection to my onePK enabled Network Element  
	config = SessionConfig(None)  
	config.set_tls_pinning('', PinningHandler(''))  
	config.transportMode = SessionConfig.SessionTransportMode.TLS  
	network_element = NetworkElement(ne_addr)

	# Try authenticating, raise error if unsuccessful  
	try:
		network_element.connect(ne_username, ne_password, config)  
	except OnepConnectionException:
		raise ValueError('Invalid Credentials or unable to reach %s.' % network_element)  

	return network_element
Пример #3
0
def ConnectNE():
    global frame
    global connect_attempt
    global ne
    global username
    global password

    ne = NetworkElement(router_ip, connection_name)
    config = SessionConfig(None)
    config.set_tls_pinning("", PinningHandler(""))
    config.transportMode = SessionConfig.SessionTransportMode.TLS
    if ne.is_connected() != 1:
        try:
            ne.connect(username, password, config)
        except:
            connect_attempt = connect_attempt + 1
            ConnectNE()
Пример #4
0
def sampleapp():
    appname = raw_input('Enter name of application : ')

    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS) #default is TLS
    if transport.lower() == "tipc" or transport == 2:
        session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    session_config.ca_certs = root_cert_path
    session_config.certfile = client_cert_path
    session_config.keyfile = client_key_path

    ne = NetworkElement(switchIP, appname)
    con = ne.connect(username, password, session_config)
    print 'Connected to host'

    print "System Name:            ", ne.properties.sys_name
    print "System Uptime:          ", ne.properties.sys_uptime
    print "Total System Memory:    ", ne.total_system_memory
    print "Free System Memory:     ", ne.free_system_memory
    print "System CPU Utilization: ", ne.system_cpu_utilization, "%\n"
    print "System Connect Time:    ", ne.get_connect_time()
    print "System Disonnect Time:  ", ne.get_disconnect_time()
    print "System __str__ Method:  ", ne
    print "Host Content String:\n",   ne.properties.content_string

    ne.disconnect()
Пример #5
0
def scaleNotification():

    for switch in switches:
        switchIP = switch[0]
        appName = switch[1]
        user = switch[2]
        pswd = switch[3]

        #
        # Set up session connection configuration and connect to the switch
        #
        ne = NetworkElement(switchIP, appName)
        if transport == 'TLS':
            session_config = SessionConfig(
                SessionConfig.SessionTransportMode.TLS)
            session_config.ca_certs = cert
            ne.connect(user, pswd, session_config)
        elif transport == 'TIPC':
            session_config = SessionConfig(
                SessionConfig.SessionTransportMode.TIPC)
            ne.connect(user, pswd, session_config)
        else:
            print "Please set-up a valid transport type: TIPC or TLS"
            exit(0)

        vty = VtyService(ne)
        vty.open()
        vlan_summary = vty.write("sh vlan summary")
        vty.close()

        vlan_sum = re.search('(?<=vlansum-all-vlan\t)(.*)', vlan_summary)

        if int(vlan_sum.group(0)) > int(scale_limits["max_vlans"]):
            string_print = "Vlan scale exceeded. Max vlan recommended:", scale_limits[
                "max_vlans"], "vlan being used :", vlan_sum.group(0)
            print string_print
            ne.create_syslog_message(
                ne.OnepSyslogSeverity.ONEP_SYSLOG_CRITICAL, str(string_print))
        print "Disconnecting from NE: ", switchIP
        ne.disconnect()
Пример #6
0
def scaleNotification():

    for switch in switches:
        switchIP = switch[0]
        appName  = switch[1]
        user     = switch[2]
        pswd     = switch[3]

        #
        # Set up session connection configuration and connect to the switch
        #
        ne = NetworkElement(switchIP, appName)
        if  transport == 'TLS':
            session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
            session_config.ca_certs = cert
            ne.connect(user, pswd, session_config)
        elif transport == 'TIPC':
            session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
            ne.connect(user, pswd, session_config)
        else:
            print "Please set-up a valid transport type: TIPC or TLS"
            exit(0)

        vty = VtyService(ne)
        vty.open()
        vlan_summary = vty.write("sh vlan summary")
        vty.close()

        vlan_sum = re.search('(?<=vlansum-all-vlan\t)(.*)',vlan_summary)

        if int(vlan_sum.group(0)) > int(scale_limits["max_vlans"]):
            string_print = "Vlan scale exceeded. Max vlan recommended:",scale_limits["max_vlans"],"vlan being used :", vlan_sum.group(0)
            print string_print
            ne.create_syslog_message (ne.OnepSyslogSeverity.ONEP_SYSLOG_CRITICAL,
                                      str(string_print));
        print "Disconnecting from NE: ",switchIP
        ne.disconnect()
Пример #7
0
switchIP = "<ip>"
user     = "******"
pswd     = "<pswd>"

prefix_addr    = "200.10.11.0"
prefix_mask    = 24
#next_hop_intf = "Ethernet1/5"
next_hop_intf  = "loopback0"
next_hop_addr  = "10.15.1.1"

#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)
if  transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd, session_config)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)


#Get a routing instance associated with a network element
routing = Routing.get_instance(ne)
Пример #8
0
    parser.add_option('-p',
                      '--password',
                      dest="password",
                      help="[Mandatory] Account Password for Login")

    (options, args) = parser.parse_args()

    if not options.ip:
        parser.print_help()
        parser.error("Provide IP Address")
    if not options.userName:
        parser.print_help()
        parser.error("Provide UserName")
    if not options.password:
        options.password = getpassword("Password:")

    # Setup a connection config with TLS pinning handler
    config = SessionConfig(None)
    config.set_tls_pinning('', PinningHandler(''))
    config.transportMode = SessionConfig.SessionTransportMode.TLS

    # Connection to my onePK enabled Network Element
    ne = NetworkElement(options.ip, 'App_Name')
    ne.connect(options.userName, options.password, config)

    # Print the information of the Network Element
    print ne

    # Finally have the application disconnect from the Network Element
    ne.disconnect()
# user     - switch userID
# pswd     - switch password
#
transport= 'TLS'
cert     = '<path>/cacert.pem'
appName  = "intf_properties_cn"
switchIP = "<ip>"
user     = "******"
pswd     = "<pswd>"

#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)
if  transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd, session_config)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)


RX_BYTES = InterfaceStatistics.InterfaceStatisticsParameter.ONEP_IF_STAT_RX_BYTES
FILTER =  InterfaceFilter(None, NetworkInterface.InterfaceTypes.ONEP_IF_TYPE_ETHERNET)
Пример #10
0
#            check tranport types supported on your image by
#            conf t --> onep --> transport  type ?
# cert     - certificate to be used for authentication in cse of TLS
#            transport
# appName  - OnePK application Name
# switchIP - management Switch IP address
user     = "******"
pswd     = "<pswd>"

crcThreshold = "10"
#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)

if  transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd, session_config)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)
#
#
# Get Interface list
#
Пример #11
0
from onep.element.NetworkElement import NetworkElement  
from onep.element.SessionConfig import SessionConfig  
from onep.core.util import tlspinning  
  
# TLS Connection
class PinningHandler(tlspinning.TLSUnverifiedElementHandler):  
   def __init__(self, pinning_file):  
       self.pinning_file = pinning_file  
   def handle_verify(self, host, hashtype, finger_print, changed):  
       return tlspinning.DecisionType.ACCEPT_ONCE  
  
# Connection to onePK enabled Network Element  
config = SessionConfig(None)  
config.set_tls_pinning('', PinningHandler(''))  
config.transportMode = SessionConfig.SessionTransportMode.TLS  
ne = NetworkElement('192.168.1.110', 'HelloWorld')  
ne.connect('cisco', 'cisco', config)  
  
# Print some info around the NetworkElement
print ne
print "System Name:            ", ne.properties.sys_name
print "System Uptime:          ", ne.properties.sys_uptime
print "Total System Memory:    ", ne.total_system_memory
print "Free System Memory:     ", ne.free_system_memory
print "System CPU Utilization: ", ne.system_cpu_utilization, "%"
print "System Connect Time:    ", ne.get_connect_time()
print "System Disconnect Time:  ", ne.get_disconnect_time()

  
# Disconnect the Network Element
ne.disconnect()  
# user     - switch userID
# pswd     - switch password
#
transport = 'TLS'
cert = '<path>/cacert.pem'
appName = "intf_properties_cn"
switchIP = "<ip>"
user = "******"
pswd = "<pswd>"

#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)
if transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd, session_config)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)

RX_BYTES = InterfaceStatistics.InterfaceStatisticsParameter.ONEP_IF_STAT_RX_BYTES
FILTER = InterfaceFilter(None,
                         NetworkInterface.InterfaceTypes.ONEP_IF_TYPE_ETHERNET)
Пример #13
0
#            check tranport types supported on your image by
#            conf t --> onep --> transport  type ?
# cert     - certificate to be used for authentication in cse of TLS
#            transport
# appName  - OnePK application Name
# switchIP - management Switch IP address
user = "******"
pswd = "<pswd>"

crcThreshold = "10"
#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)

if transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd, session_config)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)
#
#
# Get Interface list
#
Пример #14
0
switchIP = "<ip>"
user = "******"
pswd = "<pswd>"

prefix_addr = "200.10.11.0"
prefix_mask = 24
#next_hop_intf = "Ethernet1/5"
next_hop_intf = "loopback0"
next_hop_addr = "10.15.1.1"

#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)
if transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd, session_config)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)

#Get a routing instance associated with a network element
routing = Routing.get_instance(ne)

#Get RIB information
Пример #15
0
                          help="[Mandatory] Account Username for Login")
    parser.add_option('-p', '--password',dest="password",
                          help="[Mandatory] Account Password for Login")

    (options, args) = parser.parse_args()

    if not options.ip:
        parser.print_help()
        parser.error("Provide IP Address")
    if not options.userName:
        parser.print_help()
        parser.error("Provide UserName")
    if not options.password:
        options.password=getpassword("Password:")

        
    # Setup a connection config with TLS pinning handler
    config = SessionConfig(None)  
    config.set_tls_pinning('', PinningHandler(''))  
    config.transportMode = SessionConfig.SessionTransportMode.TLS  
     
    # Connection to my onePK enabled Network Element  
    ne = NetworkElement(options.ip, 'App_Name')  
    ne.connect(options.userName, options.password, config)  
     
    # Print the information of the Network Element  
    print ne
     
    # Finally have the application disconnect from the Network Element  
    ne.disconnect()
Пример #16
0
#            check tranport types supported on your image by
#            conf t --> onep --> transport  type ?
# cert     - certificate to be used for authentication in cse of TLS
#            transport
# appName  - OnePK application Name
# switchIP - management Switch IP address
# user     - switch userID
pswd     = "<pswd>"

logMsg   = "syslog generated by onePK"
#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)
if  transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)

#
# Create the syslog messange and disconnect from the device
#
print "Generating Syslog message."
Пример #17
0
from onep.element.SessionConfig import SessionConfig
from onep.core.util import tlspinning
from onep.interfaces import InterfaceFilter


# TLS Connection (This is the TLS Pinning Handler)
class PinningHandler(tlspinning.TLSUnverifiedElementHandler):
    def __init__(self, pinning_file):
        self.pinning_file = pinning_file

    def handle_verify(self, host, hashtype, finger_print, changed):
        return tlspinning.DecisionType.ACCEPT_ONCE


# Setup a connection config with TSL pinning handler
config = SessionConfig(None)
config.set_tls_pinning('', PinningHandler(''))
config.transportMode = SessionConfig.SessionTransportMode.TLS

# Connection to my onePK enabled Network Element
ne = NetworkElement('1.1.1.1', 'App_Name')
ne.connect('username', 'password', config)

try:
    # Print the information of the Network Element
    print ne

finally:
    # Finally have the application disconnect from the Network Element
    ne.disconnect()
Пример #18
0
#            check tranport types supported on your image by
#            conf t --> onep --> transport  type ?
# cert     - certificate to be used for authentication in cse of TLS
#            transport
# appName  - OnePK application Name
# switchIP - management Switch IP address
# user     - switch userID
pswd = "<pswd>"

logMsg = "syslog generated by onePK"
#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)
if transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)

#
# Create the syslog messange and disconnect from the device
#
print "Generating Syslog message."
Пример #19
0
    print "You have to specify a command (-c)"
    sys.exit()

if args.v:
    victim = args.v
else:
    print "You have to specify a victim (-u)"
    sys.exit()

password = getpass.getpass("Please enter your password: "******"Prank Listener")
cliFilter = CLIFilter(command)
clientData = None
eventHandle = router.add_cli_listener(cliListener, cliFilter, clientData)

print "-----"
print router
print "-----"
print "Waiting for command: " + command

try:
    print "-----"
    wait_for_it = raw_input("Type a key to exit script")
    router.remove_cli_listener(eventHandle)
Пример #20
0
from onep.interfaces import InterfaceStatistics
from onep.interfaces import NetworkInterface
from onep.core.util import tlspinning  
  
# TLS Connection
class PinningHandler(tlspinning.TLSUnverifiedElementHandler):  
   def __init__(self, pinning_file):  
       self.pinning_file = pinning_file  
   def handle_verify(self, host, hashtype, finger_print, changed):  
       return tlspinning.DecisionType.ACCEPT_ONCE  
  
# Connection to onePK enabled Network Element  
config = SessionConfig(None)  
config.set_tls_pinning('', PinningHandler(''))  
config.transportMode = SessionConfig.SessionTransportMode.TLS  
ne = NetworkElement('192.168.1.110', 'HelloWorld')  
ne.connect('cisco', 'cisco', config)  
  
# Print some info around the NetworkElement
print ne
print "System Name:            ", ne.properties.sys_name
print "System Uptime:          ", ne.properties.sys_uptime
print "Total System Memory:    ", ne.total_system_memory
print "Free System Memory:     ", ne.free_system_memory
print "System CPU Utilization: ", ne.system_cpu_utilization, "%"
print "System Connect Time:    ", ne.get_connect_time()
print "System Disconnect Time:  ", ne.get_disconnect_time()


GigabitEthernet1 = ne.get_interface_by_name('GigabitEthernet1')
GigabitEthernet1_Statistics =  GigabitEthernet1.get_statistics()
# Import the onePK Libraries  
from onep.element.NetworkElement import NetworkElement  
from onep.element.SessionConfig import SessionConfig
from onep.core.util import tlspinning  
from onep.interfaces import InterfaceFilter 
  
# TLS Connection (This is the TLS Pinning Handler)  
class PinningHandler(tlspinning.TLSUnverifiedElementHandler):  
   def __init__(self, pinning_file):  
       self.pinning_file = pinning_file  
   def handle_verify(self, host, hashtype, finger_print, changed):  
       return tlspinning.DecisionType.ACCEPT_ONCE  
  
# Setup a connection config with TSL pinning handler
config = SessionConfig(None)  
config.set_tls_pinning('', PinningHandler(''))  
config.transportMode = SessionConfig.SessionTransportMode.TLS  

# Connection to my onePK enabled Network Element  
ne = NetworkElement('1.1.1.1', 'App_Name')  
ne.connect('username', 'password', config)  

try:  
	# Print the information of the Network Element  
	print ne

finally:
	# Finally have the application disconnect from the Network Element  
	ne.disconnect()