Exemplo n.º 1
0
import time

from util.create_utils import random_device, create_devices, create_devices_generator

if __name__ == "__main__":

    devices = create_devices(num_devices=254, num_subnets=254)

    devices_dict = dict()
    for device in devices:
        devices_dict[device["ip"]] = device

    devices_generator = create_devices_generator(num_devices=254,
                                                 num_subnets=254)

    while True:

        ip_to_find = input("\nEnter IP address to find: ")

        if not ip_to_find:
            break

        start = time.time()

        for device in devices_generator:
            if device["ip"] == ip_to_find:
                print(f"--> found it (generator): {device}")
                generator_search_time = (time.time() - start) * 1000
                print(f"--- ---> {generator_search_time:.4f} msec")
                print(f"--- ---> id fo device: {id(device)}")
                break
from tabulate import tabulate
from util.create_utils import create_devices

# --- Main program --------------------------------------------
if __name__ == '__main__':

    devices = create_devices(num_subnets=5, num_devices=4)
    print("\n", tabulate(devices, headers="keys"))
from util.create_utils import create_devices
from pprint import pprint
from random import randint, uniform
from datetime import datetime

devices = create_devices(num_subnets=2, num_devices=25)
print("\n   NAME      VENDOR : OS      IP ADDRESS       VERSION")
print("  -----     -------   -----   --------------   -----------")
for device in devices:
    print(
        f'{device["name"]:>7}  {device["vendor"]:>10} : {device["os"]:<6}  {device["ip"]:<15}  {device["version"]}'
    )

print("\n   NAME      VENDOR : OS      IP ADDRESS       VERSION")
print("  -----     -------   -----   --------------   -----------")
for device in devices:
    if device["vendor"].lower() != "cisco":
        print(
            f'{device["name"]:>7}  {device["vendor"]:>10} : {device["os"]:<6}  {device["ip"]:<15}  {device["version"]}'
        )

print("\n----- Starting comparison of device names --------------------")
for index, device_a in enumerate(devices):
    for device_b in devices[index + 1:]:
        if device_a["name"] == device_b["name"]:
            print(
                f"Found match! {device_a['name']} for both {device_a['ip']} and {device_b['ip']}"
            )
print("----- Comparison of device names completed")

print(
Exemplo n.º 4
0
from util.create_utils import create_devices
from util.vendor import Vendor, VendorEnumInt, VendorEnumStr

devices = create_devices()

# Device Dict
# device['vendor']  = vendor
# device['os']      = os
# device['version'] = version
# device['name']    = f'{site}.{dist_frame}.{vendor}.{os}.{suffix}'
# device['ip']      = ip
for device in devices:
    if Vendor.CISCO == device['vendor']:
        print(f'\n{VendorEnumStr.CISCO.value} : {device}')

    if VendorEnumStr.JUNIPER.value == device['vendor']:
        print(f'\n{VendorEnumStr.JUNIPER.value}: {device}')
Exemplo n.º 5
0
from util.create_utils import create_devices
from pprint import pprint
from collections import namedtuple

# --- Main program --------------------------------------------
if __name__ == '__main__':

    devices = tuple(create_devices(num_devices=4, num_subnets=1))

    print("\n----- TUPLE OF DEVICES --------------------")
    pprint(devices)

    print("\n----- DEVICE AS TUPLE --------------------")
    device = ("sbx-n9kv-ao", "cisco", "Nexus9000 C9300v Chassis", "nxos",
              "10.0.1.1")

    print("  name:", device[0])
    print("vendor:", device[1])
    print(" model:", device[2])
    print("    os:", device[3])
    print("    ip:", device[4])

    print("\n----- DEVICE AS NAMED TUPLE --------------------")
    Device = namedtuple('Device', ['name', 'vendor', 'model', 'os', 'ip'])
    device = Device("sbx-n9kv-ao", "cisco", "Nexus9000 C9300v Chassis", "nxos",
                    "10.0.1.1")

    print("  name:", device.name)
    print("vendor:", device.vendor)
    print(" model:", device.model)
    print("    os:", device.os)
Exemplo n.º 6
0
from collections import namedtuple
from pprint import pprint

from util.create_utils import create_devices

if __name__ == "__main__":

    devices_tuple = tuple(create_devices(num_devices=4, num_subnets=1))

    print("\n----- TUPLE OF DEVICES")
    pprint(devices_tuple)

    print("\n----- DEVICE AS TUPLE")
    device = ("sbx-n9kv-ao", "cisco", "Nexus9000 C9300v Chassis", "nxos",
              "10.0.1.1")

    print("  name:", device[0])
    print("vendor:", device[1])
    print(" model:", device[2])
    print("    os:", device[3])
    print("    ip:", device[4])

    print("\n----- DEVICE AS NAMED TUPLE")
    Device = namedtuple("Device", ["name", "vendor", "model", "os", "ip"])
    device = Device("sbx-n9kv-ao", "cisco", "Nexus9000 C9300v Chassis", "nxos",
                    "10.0.1.1")

    print("  name:", device.name)
    print("vendor:", device.vendor)
    print(" model:", device.model)
    print("    os:", device.os)
Exemplo n.º 7
0
from datetime import datetime
from pprint import pprint
from operator import itemgetter
from random import choice
from time import sleep

import nmap
from tabulate import tabulate

from util.create_utils import create_devices

devices = create_devices(25, 1)

#########################################
print('=' * 80)

print('\n\nUsing Print')
print()
print(devices)

print('=' * 80)

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

print('\n\nUsing Pretty Print')
print()
pprint(devices)

print('=' * 80)

#########################################
Exemplo n.º 8
0
    print("=" * 80)
    print(f"{print_header}")
    print(f"    Found it: {device}")
    print(f"        in: {time:.4f} msec")
    print(f"        device id: { id(device) }")


def print_not_found(print_header, ip_to_find, time):
    print(f"{print_header}")
    print(f"    {ip_to_find} not found, try again")
    print(f"        Search time: {time:.4f} msec")


if __name__ == "__main__":

    devices = create_devices(254, 254)

    #############################################################################
    # Creating a dict of pointers to a device in devices
    devices_dict = dict()

    for device in devices:
        devices_dict[device["ip"]] = device

    while True:
        ip_to_find = input("Enter IP address to find: ")

        if not ip_to_find:
            break

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