Netwalk is a Python library to discover, parse, analyze and change Cisco switched networks

Overview

Netwalk

Netwalk is a Python library born out of a large remadiation project aimed at making network device discovery and management as fast and painless as possible.

Installation

Can be installed via pip with pip install git+ssh://[email protected]/icovada/netwalk.git

Extras

A collection of scripts with extra features and examples is stored in the extras folder

Code quality

A lot of the code is covered by tests. More will be added in the future

Fabric

This object type defines an entire switched network and can be manually populated, have switches added one by one or you can give it one or more seed devices and it will go and scan everything for you.

Auto scanning example:

from netwalk import Fabric
sitename = Fabric()
sitename.init_from_seed_device(seed_hosts=["10.10.10.1"],
                               credentials=[("cisco","cisco"),("customer","password")]
                               napalm_optional_args=[{'secret': 'cisco'}, {'transport': 'telnet'}])

This code will start searching from device 10.10.10.1 and will try to log in via SSH with cisco/cisco and then customer/password. Once connected to the switch it will pull and parse the running config, the mac address table and the cdp neighbours, then will start cycling through all neighbours recursively until the entire fabric has been discovered

Note: you may also pass a list of napalm_optional_args, check the NAPALM optional args guide for explanation and examples

Manual addition of switches

You can tell Fabric to discover another switch on its own or you can add a Switch object to .switches. WHichever way, do not forget to call refresh_global_information to recalculate neighborships and global mac address table

Example

sitename.add_switch(seed_hosts=["10.10.10.1"],
                    credentials=[("cisco","cisco"))
sitename.refresh_global_information()

Note: you may also pass a list of napalm_optional_args, check the optional args guide for explanation and examples

Structure

sitename will now contain two main attributes:

  • switches, a dictionary of {'hostname': Switch}
  • mac_table, another dictionary containing a list of all macs in the fabric, the interface closest to them

Switch

This object defines a switch. It can be created in two ways:

Automatic connection

from netwalk import Switch
sw01 = Switch(hostname="10.10.10.1")
sw01.retrieve_data(username="cisco",
                   password="cisco"})

Note: you may also pass a list of napalm_optional_args, check the optional args guide for explanation and examples

This will connect to the switch and pull all the data much like add_switch() does in Fabric

Init from show run

You may also generate the Switch device from a show run you have extracted somewhere else. This will not give you mac address table or neighborship discovery but will generate all Interfaces in the switch

from netwalk import Switch

showrun = """
int gi 0/1
switchport mode access
...
int gi 0/24
switchport mode trunk
"""

sw01 = Switch(hostname="10.10.10.1", config=showrun)

Structure

A Switch object has the following attributes:

  • hostname: the IP or hostname to connect to
  • config: string containing plain text show run
  • interfaces: dictionary of {'interface name', Interface}}
  • mac_table: a dictionary containing the switch's mac address table

Interface

An Interface object defines a switched interface ("switchport" in Cisco language) and can hold data about its configuration such as:

  • name
  • description
  • mode: either "access" or "trunk"
  • allowed_vlan: a set() of vlans to tag
  • native_vlan
  • voice_vlan
  • switch: pointer to parent Switch
  • is_up: if the interface is active
  • is_enabled: shutdown ot not
  • config: its configuration
  • mac_count: number of MACs behind it
  • type_edge: also known as "portfast"
  • bpduguard

Printing an interface yelds its configuration based on its current attributes

Trick

Check a trunk filter is equal on both sides

assert int.allowed_vlan == int.neighbors[0].allowed_vlan

Check a particular host is in vlan 10

from netaddr import EUI
host_mac = EUI('00:01:02:03:04:05')
assert fabric.mac_table[host_mac]['interface'].native_vlan == 10
You might also like...
EchoDNS - Analyze your DNS traffic super easy, shows all requested DNS traffic
EchoDNS - Analyze your DNS traffic super easy, shows all requested DNS traffic

EchoDNS - Analyze your DNS traffic super easy, shows all requested DNS traffic

A python tool auto change proxy or ip after dealy time set by user
A python tool auto change proxy or ip after dealy time set by user

Auto proxy Ghost This tool auto change proxy or ip after dealy time set by user how to run 1. Install required file ./requirements.sh 2.Enter command

This python script can change the mac address after some attack

MAC-changer Hello people, this python script was written for people who want to change the mac address after some attack, I know there are many ways t

These scripts send notifications to a Webex space when a new IP is banned by Expressway, and allow to request more info or change the ban status
These scripts send notifications to a Webex space when a new IP is banned by Expressway, and allow to request more info or change the ban status

Spam Call and Toll Fraud Mitigation Cisco Expressway release X14 is able to mitigate spam calls and toll fraud attempts by jailing the spam IP address

With the use of this tool, you can change your MAC address

Akshat0404/MAC_CHANGER This tool has to be used on linux kernel. Now o

It's a little project for change MAC address, for ethical hacking purposes

MACChangerPy It's a small project for MAC address change, for ethical hacking purposes, don't use it for bad purposes, any infringement will be your r

NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

BaseSpec is a system that performs a comparative analysis of baseband implementation and the specifications of cellular networks.
BaseSpec is a system that performs a comparative analysis of baseband implementation and the specifications of cellular networks.

BaseSpec is a system that performs a comparative analysis of baseband implementation and the specifications of cellular networks. The key intuition of BaseSpec is that a message decoder in baseband software embeds the protocol specification in a machine-friendly structure to parse incoming messages;

Evaluation of TCP BBRv1 in wireless networks

The Network Simulator, Version 3 Table of Contents: An overview Building ns-3 Running ns-3 Getting access to the ns-3 documentation Working with the d

Comments
  • _parse_config() in `netwalk/device.py` is not parsing the running config correctly

    _parse_config() in `netwalk/device.py` is not parsing the running config correctly

    netwalk/device.py has a pretty bad bug as of git hash efd5b8d5affd877df4739a639b2d2762c4d94057... explicitly:

        def _parse_config(self):
            """Parse show run
            """
            if isinstance(self.config, str):
                running = StringIO()
                running.write(self.config)
    
                # Be kind rewind
                running.seek(0)
    
                # Get show run and interface access/trunk status
                parsed_conf = CiscoConfParse(running)
    
    

    You are asking CiscoConfParse() to parse a configuration from a string. This is broken... you should be parsing a list, tuple or MutableSequence()... as such, this is one possible way to fix your call to CiscoConfParse():

    • this assumes running is a string... you can fix the problem by parsing running.splitlines()...
                assert isinstance(running, str)
                parsed_conf = CiscoConfParse(running.splitlines())
    
    opened by mpenning 3
  • Pass arbitrary neighbour filters

    Pass arbitrary neighbour filters

    Allow to specify filters when discovering switches

    https://github.com/icovada/netwalk/blob/1d4b26c1978fe818aee2eceadf396d063f5d8904/netwalk/fabric.py#L163

    opened by icovada 1
  • Interface grouping

    Interface grouping

    Implement interface grouping.

    • [x] - Add parent_interface = None attribute to Interface object

    • [x] - Define a LAG(Interface) object with the following attributes:

      • List[Interface]: child_interfaces: a list of aggregated interfaces

      It will also have a method add_child(Interface) which will append an Interface object to child_interfaces and set the parameter's .parent_interface to self

    • [x] - Add Vpc(LAG) and PortChannel(LAG) objects and their respective config parsers and generators

    opened by icovada 0
Releases(v1.1.4)
LGPL Pure Python OPC-UA Client and Server

LGPL Pure Python OPC-UA Client and Server

Free OPC-UA Library 1.2k Jan 04, 2023
A pretty quick and simple interface to paramiko SFTP

A pretty quick and simple interface to paramiko SFTP. Provides multi-threaded routines with progress notifications for reliable, asynchronous transfers. This is a Python3 optimized fork of pysftp wit

14 Dec 21, 2022
Tool for pretty printing and optimizing Lightning Network channels.

Suez Tool for pretty printing and optimizing Lightning Network channels. Installation Install poetry poetry install poetry run ./suez Channel fee poli

Pavol Rusnak 69 Nov 03, 2022
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

gRPC - An RPC library and framework gRPC is a modern, open source, high-performance remote procedure call (RPC) framework that can run anywhere. gRPC

grpc 36.6k Dec 30, 2022
Simple app that redirect fixed URL to changing URL, configurable via POST requests

This is a basic URL redirection service. It stores associations between apps and redirection URLs, for apps with changing URLs. You can then use GET r

Maxime Weyl 2 Jan 28, 2022
IP Pinger - This tool allows you to enter an IP and check if its currently connected to a host

IP Pinger - This tool allows you to enter an IP and check if its currently connected to a host

invasion 3 Feb 18, 2022
Medusa is a cross-platform agent compatible with both Python 3.8 and Python 2.7.

Medusa Medusa is a cross-platform agent compatible with both Python 3.8 and Python 2.7. Installation To install Medusa, you'll need Mythic installed o

Mythic Agents 123 Nov 09, 2022
This will generate a very basic DHCP config with use of PHPIPAM systems.

phpipam-dhcp-config-generator This will generate a very basic DHCP config with use of PHPIPAM systems. Requirements PHPIPAM Custom Fields domain_name

1 Oct 24, 2021
Converts from PC formatted MAC addresses (hardware addresses) to Cisco format or vice-versa

MAC-Converter Converts from PC formatted MAC addresses (hardware addresses) to Cisco format or vice-versa Stores the results to a file in the same dir

Stew Alexander 0 Dec 24, 2022
An ansible playbook to set up wireguard server.

Poor man's VPN (pay for only what you need) An ansible playbook to quickly set up Wireguard server for occasional personal use. It takes around five m

Amrit Bera 613 Dec 25, 2022
A TrueCharts automatic and bulk update utility

trueupdate A TrueCharts automatic and bulk update utility How to install run pip install trueupdate Please be aware you will need to reinstall after e

TrueCharts 125 Jan 04, 2023
A Python framework for interacting with Solana's Pyth network.

Pyth Network A basic Python framework for reading and decoding data regarding the Pyth network

1 Nov 29, 2021
A network address manipulation library for Python

netaddr A system-independent network address manipulation library for Python 2.7 and 3.5+. (Python 2.7 and 3.5 support is deprecated). Provides suppor

711 Jan 05, 2023
OptiPLANT is a cloud-based based system that empowers professional and non-professional data scientists to build high-quality predictive models

OptiPLANT OptiPLANT is a cloud-based based system that empowers professional and non-professional data scientists to build high-quality predictive mod

Intellia ICT 1 Jan 26, 2022
sync application configuration and settings across multiple multiplatform devices

sync application configuration and settings across multiple multiplatform devices ✨ Key Features • ⚗️ Installation • 📑 How To Use • 🤔 FAQ • 🛠️ Setu

Souvik 6 Aug 25, 2022
RollerScanner — Fast Port Scanner Written On Python

RollerScanner RollerScanner — Fast Port Scanner Written On Python Installation You should clone this repository using: git clone https://github.com/Ma

68 Nov 09, 2022
Synchronised text editor over TCP, for live editing with others.

SyncTEd Synchronised text editor over TCP, for live editing with others. Written in Python with PyGame. Run Install requirements: pip install -r requi

Marko Živić 1 May 13, 2022
ASC - Api Server Controller

ASC - Api Server Controller

Uriel Alves 1 Jan 03, 2022
Mini SCADA. Poll modbus devices by TCP/IP network.

Plans Add saving and loading devices and channels with files or db or someone else. Multitasking system for poll all devices Automatic optimization po

Efi_fi 1 Oct 25, 2021
Converts Cisco formatted MAC Addresses to PC formatted MAC Addresses

Cisco-MAC-to-PC-MAC Converts a file with a list of Cisco formatted MAC Addresses to PC formatted MAC Addresses... Ex: abcd.efgh.ijkl to AB:CD:EF:GH:I

Stew Alexander 0 Jan 04, 2022