VHost listing script

From ProjectWiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Sendy (Talk); changed back to last version by Wikisysop)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=[http://ovarynetyv.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
+
<big>vhosts - vhost listing script</big>
&lt;big&gt;vhosts - vhost listing script&lt;/big&gt;
+
  
 
__TOC__
 
__TOC__
Line 9: Line 8:
  
 
The result is something like this (but in pretty colors ^^):
 
The result is something like this (but in pretty colors ^^):
&lt;pre&gt;
+
<pre>
 
[adminuser@l33t /home/adminuser]# vhosts
 
[adminuser@l33t /home/adminuser]# vhosts
 
  Hostnames for l33t.server.com
 
  Hostnames for l33t.server.com
Line 16: Line 15:
 
241.12.191.20 = burp.bel.ch.  
 
241.12.191.20 = burp.bel.ch.  
 
241.12.191.21 = etc.etc.name.net.  
 
241.12.191.21 = etc.etc.name.net.  
&lt;/pre&gt;
+
</pre>
  
 
* 2009.05.18 ~ added better support for ipv6 ^^
 
* 2009.05.18 ~ added better support for ipv6 ^^
Line 22: Line 21:
 
==How to use it?==
 
==How to use it?==
 
Copy paste the code below into a text edit, change the IPSEARCH param, save as something like 'vhosts', change flags to executable and then type ./vhosts, iotw:
 
Copy paste the code below into a text edit, change the IPSEARCH param, save as something like 'vhosts', change flags to executable and then type ./vhosts, iotw:
&lt;source lang=&quot;bash&quot;&gt;
+
<source lang="bash">
 
emacs vhosts
 
emacs vhosts
&lt;/source&gt;
+
</source>
copy/pasta the bash source code from below, edit the IPSEARCH parameter, and save here... for instance if your first IP on box was 241.12.191.18 you'd use:&lt;bR&gt;
+
copy/pasta the bash source code from below, edit the IPSEARCH parameter, and save here... for instance if your first IP on box was 241.12.191.18 you'd use:<bR>
IPSEARCH=&quot;241&quot;
+
IPSEARCH="241"
  
 
You may also want to change the FOOTER that is displayed at bottom, or modify the colors.
 
You may also want to change the FOOTER that is displayed at bottom, or modify the colors.
  
Next make it executable, then run it:&lt;br&gt;
+
Next make it executable, then run it:<br>
&lt;source lang=&quot;bash&quot;&gt;
+
<source lang="bash">
 
chmod 755 vhosts
 
chmod 755 vhosts
 
./vhosts
 
./vhosts
&lt;/source&gt;
+
</source>
  
 
If the script is placed in the shell's search path such as /usr/local/bin/ directory the script will be available to all users.
 
If the script is placed in the shell's search path such as /usr/local/bin/ directory the script will be available to all users.
  
 
==Bash Source Code (bsd)==
 
==Bash Source Code (bsd)==
&lt;source lang=&quot;bash&quot;&gt;
+
<source lang="bash">
 
#!/usr/local/bin/bash
 
#!/usr/local/bin/bash
  
Line 48: Line 47:
 
### regexp for IP search (first octect of IP addresses should be sufficient) ###
 
### regexp for IP search (first octect of IP addresses should be sufficient) ###
 
### to search multiple subnets use the infix operator |  such as:
 
### to search multiple subnets use the infix operator |  such as:
#IPSEARCH=&quot;147|64&quot;
+
#IPSEARCH="147|64"
IPSEARCH=&quot;204&quot;;
+
IPSEARCH="204";
 
#IPv6 use the first few digits like so...
 
#IPv6 use the first few digits like so...
#IPSEARCH=&quot;2001:5c0&quot;;
+
#IPSEARCH="2001:5c0";
  
 
### colors ###
 
### colors ###
 
#title color
 
#title color
COL1=&quot;\x1b[0;31;40m&quot;;
+
COL1="\x1b[0;31;40m";
 
#ip color
 
#ip color
COL2=&quot;\x1b[0;32;40m&quot;;
+
COL2="\x1b[0;32;40m";
 
#'=' color
 
#'=' color
COL3=&quot;\x1b[0;34;40m&quot;;
+
COL3="\x1b[0;34;40m";
 
#domain color
 
#domain color
COL4=&quot;\x1b[0;33;40m&quot;;
+
COL4="\x1b[0;33;40m";
 
#error color
 
#error color
COL5=&quot;\x1b[0;31;40m&quot;;
+
COL5="\x1b[0;31;40m";
 
#colors off (back to natural terminal colors)
 
#colors off (back to natural terminal colors)
COLOFF=&quot;\x1b[0;37;00m&quot;;
+
COLOFF="\x1b[0;37;00m";
  
 
### footer (Displayed at end of list) ###
 
### footer (Displayed at end of list) ###
FOOTER=&quot;Type v6hosts for ipv6 hosts&quot;
+
FOOTER="Type v6hosts for ipv6 hosts"
  
 
### Command paths ###
 
### Command paths ###
IFCONFIG=&quot;/sbin/ifconfig&quot;;
+
IFCONFIG="/sbin/ifconfig";
GREP=&quot;/usr/bin/grep&quot;;
+
GREP="/usr/bin/grep";
AWK=&quot;/usr/bin/awk&quot;;
+
AWK="/usr/bin/awk";
HOST=&quot;/usr/bin/host&quot;;
+
HOST="/usr/bin/host";
  
 
##################
 
##################
Line 81: Line 80:
  
 
HOSTNAME=`hostname`;
 
HOSTNAME=`hostname`;
echo -en &quot;$COL1 Hostnames for $HOSTNAME\n&quot;;
+
echo -en "$COL1 Hostnames for $HOSTNAME\n";
for ip in `$IFCONFIG | $GREP inet | $AWK '{print $2}' | $GREP -E &quot;$IPSEARCH&quot;`;  
+
for ip in `$IFCONFIG | $GREP inet | $AWK '{print $2}' | $GREP -E "$IPSEARCH"`;  
 
do
 
do
   echo -ne &quot;$COL2$ip $COL3=&quot;;
+
   echo -ne "$COL2$ip $COL3=";
 
   if hostreply=`$HOST $ip`; then
 
   if hostreply=`$HOST $ip`; then
 
     domain=`echo $hostreply | $GREP domain | $AWK '{print $5}'`;  
 
     domain=`echo $hostreply | $GREP domain | $AWK '{print $5}'`;  
 
     if fwdreply=`$HOST -t A $domain`; then
 
     if fwdreply=`$HOST -t A $domain`; then
       forward=`echo &quot;$fwdreply&quot; | $AWK '{print $4}'`;
+
       forward=`echo "$fwdreply" | $AWK '{print $4}'`;
       if [ &quot;$forward&quot; = &quot;$ip&quot; ]; then
+
       if [ "$forward" = "$ip" ]; then
         error=&quot;&quot;;
+
         error="";
 
       else
 
       else
         error=&quot;$COL5(Forward lookup mismatch: $forward)&quot;;   
+
         error="$COL5(Forward lookup mismatch: $forward)";   
 
       fi
 
       fi
 
     else
 
     else
       error=&quot;$COL5(forward does not resolve)&quot;;
+
       error="$COL5(forward does not resolve)";
 
     fi
 
     fi
     echo -ne &quot;$COL4 $domain $error\n&quot;;
+
     echo -ne "$COL4 $domain $error\n";
 
   else
 
   else
     echo -ne &quot;$COL5 reverse lookup failed ._.\n&quot;;
+
     echo -ne "$COL5 reverse lookup failed ._.\n";
 
   fi
 
   fi
 
done
 
done
  
echo -ne &quot;$COLOFF\n&quot;;
+
echo -ne "$COLOFF\n";
if [ -n &quot;$FOOTER&quot; ]; then  
+
if [ -n "$FOOTER" ]; then  
 
   echo $FOOTER
 
   echo $FOOTER
 
fi
 
fi
Line 110: Line 109:
 
## erisu, 2009
 
## erisu, 2009
 
#######################
 
#######################
&lt;/source&gt;
+
</source>
  
 
==Bash Source Code (Linux)==
 
==Bash Source Code (Linux)==
Decided to post another version after fixing some issues with some Linuxs printing &quot;addr:XXX.XXX.XXX.XXX&quot; from ifconfig. Also made the command paths Linux friendly. ^_^
+
Decided to post another version after fixing some issues with some Linuxs printing "addr:XXX.XXX.XXX.XXX" from ifconfig. Also made the command paths Linux friendly. ^_^
&lt;source lang=&quot;bash&quot;&gt;
+
<source lang="bash">
 
#!/bin/bash
 
#!/bin/bash
  
Line 123: Line 122:
 
### regexp for IP search (first octect of IP addresses should be sufficient) ###
 
### regexp for IP search (first octect of IP addresses should be sufficient) ###
 
### to search multiple subnets use the infix operator |  such as:
 
### to search multiple subnets use the infix operator |  such as:
#IPSEARCH=&quot;147|64&quot;
+
#IPSEARCH="147|64"
IPSEARCH=&quot;190|200&quot;;
+
IPSEARCH="190|200";
 
#IPv6 use the first few digits like so...
 
#IPv6 use the first few digits like so...
#IPSEARCH=&quot;2001:5c0&quot;;
+
#IPSEARCH="2001:5c0";
  
 
### colors ###
 
### colors ###
 
#title color
 
#title color
COL1=&quot;\x1b[0;31;40m&quot;;
+
COL1="\x1b[0;31;40m";
 
#ip color
 
#ip color
COL2=&quot;\x1b[0;32;40m&quot;;
+
COL2="\x1b[0;32;40m";
 
#'=' color
 
#'=' color
COL3=&quot;\x1b[0;34;40m&quot;;
+
COL3="\x1b[0;34;40m";
 
#domain color
 
#domain color
COL4=&quot;\x1b[0;33;40m&quot;;
+
COL4="\x1b[0;33;40m";
 
#error color
 
#error color
COL5=&quot;\x1b[0;31;40m&quot;;
+
COL5="\x1b[0;31;40m";
 
#colors off (back to natural terminal colors)
 
#colors off (back to natural terminal colors)
COLOFF=&quot;\x1b[0;37;00m&quot;;
+
COLOFF="\x1b[0;37;00m";
  
 
### footer (Displayed at end of list) ###
 
### footer (Displayed at end of list) ###
FOOTER=&quot;Enjoy!&quot;
+
FOOTER="Enjoy!"
  
 
### Command paths ###
 
### Command paths ###
IFCONFIG=&quot;/sbin/ifconfig&quot;;
+
IFCONFIG="/sbin/ifconfig";
GREP=&quot;/bin/grep&quot;;
+
GREP="/bin/grep";
AWK=&quot;/usr/bin/awk&quot;;
+
AWK="/usr/bin/awk";
HOST=&quot;/usr/bin/host&quot;;
+
HOST="/usr/bin/host";
  
 
##################
 
##################
Line 156: Line 155:
  
 
HOSTNAME=`hostname`;
 
HOSTNAME=`hostname`;
echo -en &quot;$COL1 Hostnames for $HOSTNAME\n&quot;;
+
echo -en "$COL1 Hostnames for $HOSTNAME\n";
for tip in `$IFCONFIG | $GREP inet | $AWK '{print $2}' | $GREP -E &quot;$IPSEARCH&quot;`;
+
for tip in `$IFCONFIG | $GREP inet | $AWK '{print $2}' | $GREP -E "$IPSEARCH"`;
 
do
 
do
   IFS=&quot;:&quot;
+
   IFS=":"
 
   zip=($tip);
 
   zip=($tip);
 
   ip=${zip[1]};
 
   ip=${zip[1]};
   echo -ne &quot;$COL2$ip $COL3=&quot;;
+
   echo -ne "$COL2$ip $COL3=";
 
   if hostreply=`$HOST $ip`; then
 
   if hostreply=`$HOST $ip`; then
 
     domain=`echo $hostreply | $GREP domain | $AWK '{print $5}'`;
 
     domain=`echo $hostreply | $GREP domain | $AWK '{print $5}'`;
 
     if fwdreply=`$HOST -t A $domain`; then
 
     if fwdreply=`$HOST -t A $domain`; then
       forward=`echo &quot;$fwdreply&quot; | $AWK '{print $4}'`;
+
       forward=`echo "$fwdreply" | $AWK '{print $4}'`;
       if [ &quot;$forward&quot; = &quot;$ip&quot; ]; then
+
       if [ "$forward" = "$ip" ]; then
         error=&quot;&quot;;
+
         error="";
 
       else
 
       else
         error=&quot;$COL5(Forward lookup mismatch: $forward)&quot;;
+
         error="$COL5(Forward lookup mismatch: $forward)";
 
       fi
 
       fi
 
     else
 
     else
       error=&quot;$COL5(forward does not resolve)&quot;;
+
       error="$COL5(forward does not resolve)";
 
     fi
 
     fi
     echo -ne &quot;$COL4 $domain $error\n&quot;;
+
     echo -ne "$COL4 $domain $error\n";
 
   else
 
   else
     echo -ne &quot;$COL5 reverse lookup failed ._.\n&quot;;
+
     echo -ne "$COL5 reverse lookup failed ._.\n";
 
   fi
 
   fi
 
done
 
done
  
echo -ne &quot;$COLOFF\n&quot;;
+
echo -ne "$COLOFF\n";
if [ -n &quot;$FOOTER&quot; ]; then
+
if [ -n "$FOOTER" ]; then
 
   echo $FOOTER
 
   echo $FOOTER
 
fi
 
fi
Line 188: Line 187:
 
## erisu, 2009
 
## erisu, 2009
 
#######################
 
#######################
&lt;/source&gt;
+
</source>

Latest revision as of 14:50, 7 November 2011

vhosts - vhost listing script

Contents

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. Fun fun fun ^^

The script below provides a means to list the names of all the IPs on the server as well as performing some checks such as checking that the forward host-name resolves to the reverse IP. In this way its useful as a diagnostic tool for shell administrators as well as providing a list of locally available vhosts for users.

The result is something like this (but in pretty colors ^^):

[adminuser@l33t /home/adminuser]# vhosts
 Hostnames for l33t.server.com
241.12.191.18 = l33t.server.com. 
241.12.191.19 = my.hostname.org. 
241.12.191.20 = burp.bel.ch. 
241.12.191.21 = etc.etc.name.net. 
  • 2009.05.18 ~ added better support for ipv6 ^^

How to use it?

Copy paste the code below into a text edit, change the IPSEARCH param, save as something like 'vhosts', change flags to executable and then type ./vhosts, iotw:

emacs vhosts

copy/pasta the bash source code from below, edit the IPSEARCH parameter, and save here... for instance if your first IP on box was 241.12.191.18 you'd use:
IPSEARCH="241"

You may also want to change the FOOTER that is displayed at bottom, or modify the colors.

Next make it executable, then run it:

chmod 755 vhosts
./vhosts

If the script is placed in the shell's search path such as /usr/local/bin/ directory the script will be available to all users.

Bash Source Code (bsd)

#!/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";
#IPv6 use the first few digits like so...
#IPSEARCH="2001:5c0";
 
### 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";
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}' | $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
 
## erisu, 2009
#######################

Bash Source Code (Linux)

Decided to post another version after fixing some issues with some Linuxs printing "addr:XXX.XXX.XXX.XXX" from ifconfig. Also made the command paths Linux friendly. ^_^

#!/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="190|200";
#IPv6 use the first few digits like so...
#IPSEARCH="2001:5c0";
 
### 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="Enjoy!"
 
### Command paths ###
IFCONFIG="/sbin/ifconfig";
GREP="/bin/grep";
AWK="/usr/bin/awk";
HOST="/usr/bin/host";
 
##################
#Code goes here
##################
 
HOSTNAME=`hostname`;
echo -en "$COL1 Hostnames for $HOSTNAME\n";
for tip in `$IFCONFIG | $GREP inet | $AWK '{print $2}' | $GREP -E "$IPSEARCH"`;
do
  IFS=":"
  zip=($tip);
  ip=${zip[1]};
  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
 
## erisu, 2009
#######################
Personal tools
irssi scripts
eggdrop scripts