find switch port for specified hostname
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 22 Jun 2018 10:17:19 +0000 (12:17 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 22 Jun 2018 10:17:19 +0000 (12:17 +0200)
find-port-for-hostname [new file with mode: 0755]

diff --git a/find-port-for-hostname b/find-port-for-hostname
new file mode 100755 (executable)
index 0000000..f9f8c89
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh -e
+
+host=$1
+
+test -z "$host" && echo "Usage: $0 hostname" && exit 1
+
+sudo id
+
+ping -q -c 1 $host
+mac=`sudo arp -a | grep $host | cut -d' ' -f4 | sort -u`
+grep -r -i $mac /dev/shm/snmp-mac-port/ | tee /dev/shm/port.$host | egrep -v '(23|24|48|49)$' # remove trunk ports
+
+echo "# "`cat /dev/shm/port.$host | cut -d: -f2- | cut -d' ' -f1 | sort -u | wc -l`" switches have $host mac $mac"