Created
March 25, 2011 04:14
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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