Skip to main content

Automatically fetch MAC/IP address tables (ARP and IPv6 neighbors) from devices and build MAC address to BGP peer ASN mappings.

Project description

mac-to-peer

Automatically fetch MAC/IP address tables (ARP and IPv6 neighbors) from devices and build MAC address to BGP peer ASN mappings.

Particularly focused on building pmacct’s bgp_peer_src_as_map file.

router1#show ip arp
Protocol  Address          Age (min)  Hardware Addr   Type   Interface
Internet  192.0.2.1             101   0000.5E00.5300  ARPA   TenGigabitEthernet0/0/0

router1#show bgp ipv4 unicast neighbors 192.0.2.1
BGP neighbor is 192.0.2.1, remote AS 65536, internal link
...

Expected: 00:00:5E:00:53:00 -> AS65536

JSON output format:

$ mactopeer -u pierky -p - --hostname router1.example.com
Enter password:
{
  "router1.example.com": {
    "00:00:5E:00:53:00": {
      "ifaces": [
        "TenGigabitEthernet0/0/0"
      ],
      "ip_addrs": [
        "192.0.2.1"
      ],
      "peer_asns": {
        "65536": {
          "description": "my-peer",
          "ip_addrs": [
            "192.0.2.1"
          ]
        }
      }
    }
  }
}

pmacct output format:

$ mactopeer -u pierky -p - --devices device.json -f pmacct
Enter password:
id=65536      ip=203.0.113.1          src_mac=00:00:5E:00:53:00

Installation and dependencies

Install the program using pip:

pip install mactopeer

The script uses the NAPALM library to connect to network devices and to fetch data from them: you must install the whole library…

pip install napalm

… or at least the subset of network drivers needed to connect to the devices you actually need:

pip install napalm-ios napalm-junos

For more details, the full list of network drivers and their dependencies please see the official NAPALM documentation.

Usage and features

The --help shows all the options this program offers. See its output in USAGE.rst.

A list of devices can be provided using an input JSON file: for details about its schema please run mactopeer --help-devices. See its output in USAGE.rst.

Filters can be set to skip entries on the basis of their MAC address, IP address or resulting peer ASN.

Multithreading is also supported to fetch information from more than one device concurrently.

The list of supported devices can be found in the Supported Devices section of the NAPALM’s documentation website. All those implementing the get_arp_table and get_bgp_neighbors methods should work: at time of writing they are EOS, IOS, IOSX-R, JunOS, NXOS, VyOS.

Caveats

  • Currently VRF support is missing, mostly because it’s not included in NAPALM yet.

  • IPv6 neighbors table can only be fetched if a not yet released version of NAPALM is used, that is one which includes this pull request. To avoid the WARNING - Skipping IPv6 neighbors table message please use the --arp-only argument.

Author

Pier Carlo Chiodi - https://pierky.com/

Blog: https://blog.pierky.com/ Twitter: @pierky

Change log

v0.1.0

First release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mactopeer-0.1.0.tar.gz (9.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page