#!/usr/bin/perl # $Id: mkinterface,v 1.3 2007/08/16 14:55:10 ksb Exp $ # Convert a netlint report into interface.cl style (petef,ksb) use strict; my($NETLINT) = "/var/netlint"; # Convert a mac from 0xAABBCCDDEEFF or 8:0:1:aa:bb:ff or (petef,ksb) # 8.0.1.2.3.4 to Cisco 0080.b01d.c0de format. sub CiscoMac($) { my($mac) = shift; my(@macs); $mac =~ tr/[A-Z]/[a-z]/; if ($mac =~ m/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f]\.[0-9a-f][0-9a-f][0-9a-f][0-9a-f]\.[0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/) { return $mac; } if ($mac =~ s/^0x// || $mac =~ m/^[^.:]*$/) { @macs = unpack("a2a2a2a2a2a2", $mac); } else { @macs = split /[:.]/, $mac; } $mac = join('', map { substr("00$_", -2, 2) } @macs); $mac =~ s/(....)(....)(....)/$1.$2.$3/; return $mac; } my($host) = $ARGV[0] || die "not enough args\n"; my(@ints); my($defmac) = ''; open(INPUT, "$NETLINT/$host"); $host =~ s/\..*//; while() { next unless s/^IP_IFS: *//; chomp($_); $defmac = $1 if /([0-9a-fA-F]{1,2}:[0-9a-fA-F]{1,2}:[0-9a-fA-F]{1,2}:[0-9a-fA-F]{1,2}:[0-9a-fA-F]{1,2}:[0-9a-fA-F]{1,2})/; @ints = split /,\s*/; foreach(@ints) { /([^(]*)\(([0-9.]+)\s*([0-9a-z:.]*)\)/i; my($interface, $ip, $macaddr) = ($1, $2, $3); $interface =~ s/:/,/; $macaddr ||= $defmac; $macaddr = CiscoMac($macaddr); print "$host:$interface:$ip:$macaddr:\n"; } } close(INPUT); exit 0;