Category Archives: Networking

Better way of formatting Mac Addresses in Python

Following up on my Formating mac addresses using python post I have a better way of using Mac addresses.  I have been using the netaddr library for ip and mac address manipulations.  To convert a binary mac address to an EUI object you can use the following code

import netaddr
from netaddr import EUI

def convertMac(octet):
"""
This Function converts a binary mac address to a hexadecimal string representation
"""
return EUI(netaddr.strategy.eui48.packed_to_int(octet))

with the EUI object you have multiple options to format with.

>>> from netaddr import EUI
>>> import netaddr
>>> mac = EUI('01-23-45-67-89-0A')
>>> print mac
01-23-45-67-89-0A
>>>
>>> mac.dialect = netaddr.mac_cisco
>>> print mac
0123.4567.890a
>>>
>>> mac.dialect = netaddr.mac_unix
>>> print mac
1:23:45:67:89:a
>>>
>>> mac.dialect = netaddr.mac_bare
>>> print mac
01234567890A
>>>
>>> mac.dialect = netaddr.mac_unix_expanded
>>> print mac
01:23:45:67:89:0a
>>> mac.dialect = netaddr.mac_eui48
>>> print mac
01-23-45-67-89-0A

Mercurial for Tracking Cisco Configs

As I have been working with different routers I have squired a small repository of configuration files that I use for examples, backups, and ways of remembering the way the network was set up before a change. At the start I maintained each config as a separate file, usually containing the date (i.e. router1-071012.cfg). While that worked for a while it got cumbersome when I wanted to track more than one legacy version of a config file. Continue reading

Allowing UNI or protected ports on Cisco switch to reach each other using IP

When deploying Metro Ethernet service and Colocated services, best practice it to put the ports in protected mode or uni. This is to prevent customers from causing interference to each other with layer2 protocols. It also allows the user of service provider traffic filtering. The downside is without additional configuration, customer traffic to another customer is blackholed when they exist in the same subnet. Continue reading

Editing Cisco ACLs Inline

Are you annoyed at having to copy an ACL to a text editor to add a line?   After that, you have to either remove the ACL entirely or add the new version with a different name and update all the interfaces to use the new name.  I have been using the following trick recently to edit ACLs inline without having the complete remove or rewrite the ACL.
Continue reading

Setting up 802.q and switch ports in an ASR9000

IOS-XR has a structure that is very different than standard IOS. I would recomend checking the different documentation at Cisco.com this post is not going to explain things like having to commit a config before it is applied… etc, but rather I am going to assume you have read the getting started guide.

The project that lead to me being exposed to an ASR9000 is a network migration that is replacing a pair of 7200 routers and a 3750 switch (which is only being used for layer2 features) with a single ASR9000 with Redundant RSPs. The ASR has a 40 port gig module and a 4 port 10 gig module. To replace the switch I need to add ports to a “vlan” and trunk those vlans to downstream switches at other pops. Continue reading

Formating Mac addresses using python

UPDATE

A better way to do this is using the netaddr library.  as shown in this post Better way of formatting mac addresses in python

 

I have a large set of shell script that I had written in shell, which I have been converting to python based scripts.  I found using python I could better extend my scripts and reuse code.  I also appreciate that python is a full object oriented programming language, with a very powerful set of standard libraries and many optional third party libraries.
Continue reading