Exemplo n.º 1
0
async def task():
    """
    Async function
    """

    # Read a text file with 2 lines: 1 with a login and the other one with a password
    with open("credentials.txt") as f:
        credentials = f.read()

    # Extract the 2 data from the text read
    (login, password) = credentials.split()

    # Variable declaration with the login and password read
    my_device = {
        "ip": "192.168.0.2",
        "username": login,
        "password": password,
        "device_type": "cisco_s300",
    }

    # Creation of a device
    async with netscud.ConnectDevice(**my_device) as device:

        # Sending command
        output = await device.send_command("show vlan")

        # Display message
        print(output)
Exemplo n.º 2
0
async def run_client(**host):
    """
    async function used by each device individually

    """

    # Default returned value
    output = ""

    try:

        # Connection to the device
        async with netscud.ConnectDevice(**host) as device:

            # Sending command
            output = await device.get_version()

            # Display message
            print("output: '" + str(output) + "'")

    except:

        # If something is wrong then an error message is displayed
        print("Error")

    # Return result
    return output
Exemplo n.º 3
0
async def task():
    """
    Async function
    """

    my_device = {
        "ip": "192.168.0.16",
        "username": "******",
        "password": "******",
        "device_type": "cisco_ios",
    }

    # Creation of a device
    sw1 = netscud.ConnectDevice(**my_device)

    # Connection to the device
    await sw1.connect()

    # Command to send
    cmd = "show interfaces description"

    # Sending command
    output = await sw1.send_command(cmd)

    # Display message
    print(output)

    # Disconnection
    await sw1.disconnect()
Exemplo n.º 4
0
async def task():
    """
    Async function
    """

    my_device = {
        "ip": "192.168.0.16",
        "username": "******",
        "password": "******",
        "device_type": "cisco_ios",
    }

    # Connection to the device
    async with netscud.ConnectDevice(**my_device) as sw1:

        # Commands to send
        cmds = [
            "interface FastEthernet1/0",
            "ip address 1.1.1.1 255.255.255.0",
            "no shutdown",
        ]

        # Sending command
        output = await sw1.send_config_set(cmds)

        # Display message
        print(output)
Exemplo n.º 5
0
async def task():
    """
    Async function
    """

    my_device = {
        "ip": "192.168.0.16",
        "username": "******",
        "password": "******",
        "device_type": "cisco_ios",
    }

    try:

        # Connection to the device
        async with netscud.ConnectDevice(**my_device) as sw1:

            # Command to send
            cmd = "show interfaces subscription"

            try:

                # Sending command
                output = await sw1.send_command(cmd)

                # Display message
                print(output)

            except Exception as error:

                # Error during connection

                # Display message
                print("Error:\n" + str(error))

                # Leave the program
                return

    except Exception as error:

        # Error during connection

        # Display message
        print("Error: " + str(error))

        # Leave the program
        return
Exemplo n.º 6
0
async def task():
    """
    Async function
    """

    my_device = {
        "ip": "192.168.0.2",
        "username": "******",
        "password": "******",
        "device_type": "cisco_s300",
    }

    # Creation of a device
    async with netscud.ConnectDevice(**my_device) as device:

        # Sending command
        output = await device.get_model()

        # Display message
        print(output)
Exemplo n.º 7
0
async def task():
    """
    Async function
    """

    my_device = {
        "ip": "192.168.0.2",
        "username": "******",
        "password": "******",
        "device_type": "cisco_s300",
        "protocol": "telnet",
    }

    # Creation of a device
    async with netscud.ConnectDevice(**my_device) as sw1:

        # Command to send
        cmd = "show ip route"

        # Sending command
        output = await sw1.send_command(cmd)

        # Display message
        print(output)