Created
May 31, 2013 22:28
-
-
Save stefanlasiewski/5688376 to your computer and use it in GitHub Desktop.
Shell script scripts to get hostnames from IPs and VIPs listed in ifconfig
This file contains 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 | |
# Shell script scripts to get hostnames from IPs and VIPs listed in ifconfig | |
# ------------------------------------------------------------------------- | |
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/> | |
# This script is licensed under GNU GPL version 2.0 or above | |
# ------------------------------------------------------------------------- | |
# This script is part of nixCraft shell script collection (NSSC) | |
# Visit http://bash.cyberciti.biz/ for more information. | |
# ------------------------------------------------------------------------- | |
# Based off of http://bash.cyberciti.biz/misc-shell/read-local-ip-address/ | |
PATH=$PATH:/sbin | |
# Get OS name | |
OS=`uname` | |
IPS="" # store IPS | |
case $OS in | |
Linux) | |
IPS=`ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'` | |
;; | |
FreeBSD|OpenBSD|Darwin) | |
IPS=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` | |
;; | |
SunOS) | |
IPS=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` | |
;; | |
*) | |
IPS="Unknown" | |
;; | |
esac | |
for IP in $IPS | |
do | |
# Need HNAME so that one entry prints per line, even for null records. | |
HNAME=`dig +short -x $IP` | |
echo "$IP = $HNAME" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment