VHost listing script

From ProjectWiki
(Difference between revisions)
Jump to: navigation, search
(New page: <big>vhosts - vhost listing script</big> ==What is it?== Servers dedicated for irc chat clients (aka: shell servers) often provide multiple IP addresses with cute names. These are commonly...)
 
Line 6: Line 6:
  
 
==Bash Source Code==
 
==Bash Source Code==
<source lang="bash>
+
<source lang="bash">
 
#!/usr/local/bin/bash
 
#!/usr/local/bin/bash
  

Revision as of 00:50, 2 March 2009

vhosts - vhost listing script

What is it?

Servers dedicated for irc chat clients (aka: shell servers) often provide multiple IP addresses with cute names. These are commonly known as 'vanity hosts' or vhosts and usually have colorful or descriptive IP names that the user may choose for outgoing connections so that their hostname shows up as fancy.host.name.com instead of 1-124-51.lame.broadbandsupplier.com.

The script below provides a means to list the IPs and names assigned to them as well as performing some checks such as checking that the forward hostname resolves to the reverse IP.

Bash Source Code

#!/usr/local/bin/bash
 
#####################
# Settings
#####################
 
### regexp for IP search (first octect of IP addresses should be sufficient) ###
### to search multiple subnets use the infix operator |  such as:
#IPSEARCH="147|64"
IPSEARCH="204";
 
### colors ###
#title color
COL1="\x1b[0;31;40m";
#ip color
COL2="\x1b[0;32;40m";
#'=' color
COL3="\x1b[0;34;40m";
#domain color
COL4="\x1b[0;33;40m";
#error color
COL5="\x1b[0;31;40m";
#colors off (back to natural terminal colors)
COLOFF="\x1b[0;37;00m";
 
### footer (Displayed at end of list) ###
FOOTER="Type v6hosts for ipv6 hosts"
 
### Command paths ###
IFCONFIG="/sbin/ifconfig";
GREP="/usr/bin/grep";
AWK="/usr/bin/awk";
CUT="/usr/bin/cut";
HOST="/usr/bin/host";
 
##################
#Code goes here
##################
 
HOSTNAME=`hostname`;
echo -en "$COL1 Hostnames for $HOSTNAME\n";
for ip in `$IFCONFIG | $GREP inet | $AWK '{print $2}' | $CUT -d: -f2 | $GREP -E "$IPSEARCH"`; 
do
  echo -ne "$COL2$ip $COL3=";
  if hostreply=`$HOST $ip`; then
    domain=`echo $hostreply | $GREP domain | $AWK '{print $5}'`; 
    if fwdreply=`$HOST -t A $domain`; then
      forward=`echo "$fwdreply" | $AWK '{print $4}'`;
      if [ "$forward" = "$ip" ]; then
        error="";
      else
        error="$COL5(Forward lookup mismatch: $forward)";   
      fi
    else
      error="$COL5(forward does not resolve)";
    fi
    echo -ne "$COL4 $domain $error\n";
  else
    echo -ne "$COL5 reverse lookup failed ._.\n";
  fi
done
 
echo -ne "$COLOFF\n";
if [ -n "$FOOTER" ]; then 
  echo $FOOTER
fi
Personal tools
irssi scripts
eggdrop scripts