Randomly Expressed


Welcome to my blog “randomly expressed”. I created this website to publish helpful tips. It’s mainly technology driven, but I will blog about other topics. I am a Unix sysadmin that is always looking to learn new things. My goal is to be able to share knowledge that others may find useful. xkcd.com

Continue Reading »


Connect With US

Connect with us on the following social networking sites.

Most Popular Posts.

Add Some Content to This Area

You should either deactivate this panel on the Theme Settings page, or add some content via the Widgets page in your WordPress dashboard.

MAC switch port script

By on February 16, 2017 in Technology with No Comments

The following is a bash script to find out what Cisco switch and port your MAC OSX is connected to. It will check if your connected to a Cisco IP phone or a Cisco switch. For those of you that use Cisco IP phones you can daisy chain your internet connection through your phone since it requires POE and then connect your MAC’s ethernet connection to your phone. The script will check and determine what NIC you are connected and then run a tcpdump to listen for the Cisco packet that carriers the switch and port information.

uid=/usr/bin/id -u
if [[ $uid -gt 0 ]] ; then
echo "You must run this script with root privileges. Try 'sudo $0'."
exit 1
echo "It may take up to 1 minute in order to gather the cisco packet."
NIC="$(netstat -i | grep 10.0 | awk '{print $1}' | xargs | awk '{print $2}')"
if [[ "$NIC" == "en0" ]]; then
echo "You are connected via WiFi please connect via ethernet port and re-run the script."
exit 1
INFO="$(/usr/sbin/tcpdump -A -e -vvv-i $NIC -s 1500 -c 1 'ether[20:2] == 0x2000')"
SWITCH="$(echo "$INFO" | grep "Management Address" | awk '{print $10}')"
PORT="$(echo "$INFO" | grep Port-ID | awk '{print $7}')"
if [[ ! -z "$SWITCH" ]]; then
echo "$(hostname) is located on $SWITCH port $PORT."
SWITCH="$(echo "$INFO" | grep Platform | awk '{print $10}')"
PORT="$(echo "$INFO" | grep Port-ID | awk '{print$7$8}')"
echo "$(hostname) is connected to a Cisco IP Phone $SWITCH $PORT."

Facebook Comments

Tagged With: ,

Post a Comment

Your email address will not be published. Required fields are marked *