Skip to content

Instantly share code, notes, and snippets.

@mikeweber
Created March 25, 2011 04:14
Show Gist options
  • Save mikeweber/886354 to your computer and use it in GitHub Desktop.
Save mikeweber/886354 to your computer and use it in GitHub Desktop.
Get your router's IP address and add it to your current ~/.ssh/config file
#!/bin/sh
SNMPKEY="public"
HOMEPATH="/Users/username"
SSH_CONFIG="$HOMEPATH/Dropbox/dotfiles/.ssh/config"
if [ $# = 1 ] ; then
SNMPKEY="$1"
fi
IFS=" "
set -- $(netstat -nr | egrep '^0.0.0.0|^default')
ROUTER=$2
set -- $(snmpwalk -Os -c "$SNMPKEY" -v 1 "$ROUTER" ipRouteNextHop.0.0.0.0)
set -- $(snmpwalk -Os -c "$SNMPKEY" -v 1 "$ROUTER" ipRouteNextHop.$4)
sed -e "s/HostName [0-9.]*/HostName $4/" $SSH_CONFIG > $HOMEPATH/config.tmp
mv $HOMEPATH/config.tmp $SSH_CONFIG
echo $4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment