def option(number):
    print('\r')
    if number == 1:
        quickstart(switch, show_int, max_threads=2)
        second_run_job()
    elif number == 2:
        print('\r')
        quickstart(switch, show_mac, max_threads=2)
        second_run_job()
    elif number == 3:
        print('\r')
        quickstart(
            switch, power_cycle, max_threads=2
        )  # calling the start function to take all variables and input into reboot_device function.
        second_run_job()
    elif number == 4:
        exit_script()
Beispiel #2
0
#!/usr/bin/env python
from Exscript.util.match    import any_match
from Exscript.util.template import eval_file
from Exscript.util.start    import quickstart

def do_something(conn):
    conn.execute('ls -1')
    files = any_match(conn, r'(\S+)')
    print "Files found:", files

# Open a connection (Telnet, by default) to each of the hosts, and run
# do_something(). To open the connection via SSH, you may prefix the
# hostname by the protocol, e.g.: 'ssh://hostname', 'telnet://hostname',
# etc.
quickstart(('localhost', 'otherhost'), do_something)
Beispiel #3
0
#!/usr/bin/env python
from Exscript.util.template import eval_file
from Exscript.util.start import quickstart


def do_something(job, host, conn):
    assert conn.guess_os() == 'shell'
    conn.execute('ls -1')
    eval_file(conn, 'template.exscript', foobar='hello-world')

quickstart('ssh://xpc3', do_something)
Beispiel #4
0
#!/usr/bin/env python
from Exscript.util.match import any_match
from Exscript.util.template import eval_file
from Exscript.util.start import quickstart


def do_something(job, host, conn):
    conn.execute('ls -1')
    files = any_match(conn, r'(\S+)')
    print "Files found:", files


# Open a connection (Telnet, by default) to each of the hosts, and run
# do_something(). To open the connection via SSH, you may prefix the
# hostname by the protocol, e.g.: 'ssh://hostname', 'telnet://hostname',
# etc.
quickstart(('localhost', 'otherhost'), do_something)
from Exscript.util.start import quickstart
from Exscript.util.file import get_hosts_from_file, get_accounts_from_file
from Exscript import Account

command = input("enter command: ")


def do_something(job, host, conn):
    conn.execute('term len 0')
    conn.execute(command)


accounts = get_accounts_from_file('accounts.cfg')
hosts = get_hosts_from_file('hostlist.txt', default_protocol='ssh2')
quickstart(hosts, do_something, max_threads=15, verbose=1)
Beispiel #6
0
#!/usr/bin/env python
from Exscript.util.template import eval_file
from Exscript.util.start import quickstart


def do_something(conn):
    assert conn.guess_os() == 'shell'
    conn.execute('ls -1')
    eval_file(conn, 'template.exscript', foobar='hello-world')


quickstart('ssh://xpc3', do_something)

def mass_commands(job, hosts, conn):
    #    conn.send("enable\r")
    #    conn.auto_app_authorize(accounts)
    conn.execute('conf t')
    mass_commands_file = 'mass_commands.txt'
    with open(mass_commands_file, 'r') as f:
        for line in f:
            conn.execute(line)

            # conn.execute('show run')
            # get hostname of the device
            # hostname = eum.first_match(conn, r'^hostname\s(.*)$')
            # cfg_file = '/home/xxxx/python/configs/firewalls/' + hostname.strip() + '.cfg'
            # config = conn.response.splitlines()
            # some clean up
            # for i in range(3):
            #    config.pop(i)
            # config.pop(-0)
            # config.pop(-1)
            # write config to file

            # with open(cfg_file, 'w') as f:
            #    for line in config:
            #        f.write(line + '\n')


# eus.start(accounts, hosts, mass_commands, max_threads = 8)
eus.quickstart(hosts, mass_commands, max_threads=8)
Beispiel #8
0
    except:
        print 'Unable to upload to MongoDB, oh well!'

def draw_isis(job, host, conn):
    """"Use Exscript to login to a Cisco IOS router, get the IS-IS database,
    and parse+analyze+draw the IS-IS topology."""
    # host.name is provided by Exscript, returns name of current host
    region = router_region[host.name]
    conn.send("enable\r")
    conn.app_authorize()
    conn.execute('term len 0')
    conn.execute('show isis database detail')
    isis_db = conn.response
    # Got the database, now parse it into a DiGraph
    topo = isis_db_to_digraph(isis_db, region)
    # Got topology DiGraph, now analyze it for potential SPOF impacts
    impacts = spofs(topo)
    # Got topology & SPOF impacts, now save the diagram (SVG) in the current
    # working directory, and try to upload the topology XML data (SVG+GraphML)
    # to MongoDB server
    topo_entry = draw(topo, impacts, save_svg=True, return_svg=True, return_graphml=True)
    topo_entry['region'] = region
    topo_entry['timestamp'] = topo.graph['timestamp']
    mongo_save(topo_entry)
    # use conn.send to 'exit' because conn.execute waits for a normal
    # prompt that will never come, and cause a script timeout error.
    conn.send('exit')

# Open a connection to each router, and do draw_isis().
quickstart(routers, draw_isis, max_threads = 3)
Beispiel #9
0
import Exscript

from Exscript.util.start import quickstart
from Exscript.util.file import get_hosts_from_file


def do_something(job, host, conn):
    conn.execute('conf t')
    conn.execute('interface lo4')
    conn.execute('des exscript')
    conn.execute('end')


hosts = get_hosts_from_file('hosts.txt')
quickstart(hosts, do_something, max_threads=3)

#quickstart does the following:
#1.It prompts the user for a username and a password.
#2.It connects to the specified host, using the specified protocol.
#3.It logs in using the given login details.
#4.It calls our do_something() function.
#5.When do_something() completes, it closes the connection.

#max_threads = 3 does the following:
#This tells Exscript to open three network connections in parallel.
import Exscript


from Exscript.util.start import quickstart
from Exscript.util.file  import get_hosts_from_file


def do_something(job, host, conn):
    conn.execute('conf t')
    conn.execute('interface lo4')
    conn.execute('des exscript')
    conn.execute('end')


hosts = get_hosts_from_file('hosts.txt')
quickstart(hosts, do_something, max_threads = 3)


#quickstart does the following:
#1.It prompts the user for a username and a password.
#2.It connects to the specified host, using the specified protocol.
#3.It logs in using the given login details.
#4.It calls our do_something() function.
#5.When do_something() completes, it closes the connection.


#max_threads = 3 does the following:
#This tells Exscript to open three network connections in parallel.

Beispiel #11
0
#!/usr/bin/env python

import Exscript.util.file as euf
import Exscript.util.start as eus
import Exscript.util.match as eum
from Exscript import Account

hosts = euf.get_hosts_from_file('ips.txt')

threads = 8

print "\nClearing crypto sa sessions with: " + str(threads) + " threads\n"


def clear_sa(job, hosts, conn):
    conn.execute('clear crypto sa')


eus.quickstart(hosts, clear_sa, max_threads=threads)