Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

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

PYPIVersion PythonVersions BuildStatus Coveralls

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. Useful to exclude iBGP sessions or to handle exceptions.

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.

Integration with PeeringDB

The --use-peeringdb argument can be used to fetch missing peers’ ASNs from PeeringDB, for example in case of multi-lateral peering (such as route servers at IXPs). In this case, routers have not a straight mapping between IP address and BGP neighborship, so the IP address is used to look into PeeringDB records to find the network which is using it.

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.3.0

  • Improvement: made use_peeringdb an attribute of devices’ declaration.
  • Improvement: some fixes.

Also, the tool can be used as a library now.

v0.2.0

  • New: IP based filters extended to the use of prefixes too.
  • New: --use-peeringdb argument to fetch missing peers’ ASNs from PeeringDB (e.g. in case of multi-lateral peering at IXPs).

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.

Filename, size & hash SHA256 hash help File type Python version Upload date
mactopeer-0.3.0.tar.gz (33.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page