
                                        /-----------------------------\
                                        | Xine - issue #2 - Phile 020 |
                                        \-----------------------------/

#!/usr/bin/perl

# IP scanner - b0z0/iKx
# Scans a range of IPs and tries to determinate if the hosts are
# alive. It can also do name server queries to see if something
# respondes to those scanned IPs. FPing is needed!
#
#
# Sample usage:
#  ipscan -H 123.10.10.4 -e 20
# Will scan IPs from 123.10.10.4 up to 123.10.10.20
# Run without command line parameters for more help!
#

require "getopt.pl";
$|=1;

&Getopt('Hetz');			# Get command line options
$host=$opt_H;
$endipscan=$opt_e;
$pingto=$opt_t;
$dohost=$opt_z;


# default options
$pingto=5000 if (($pingto eq '') || ($pingto <= 250));
$dohost=0 if ($dohost eq '');


print "\nIPScan - by b0z0/iKx\n";
if (($host eq '') || ($endipscan eq '')) 
{
  print "usage: ipscan\n";
  print "   -H [first ip] => first IP from we will start thescan\n";
  print "   -e [last nr]  => last IP that we will scan\n";
  print "   -t [msecs]    => timeout in milisecs\n";
  print "   -z 1          => do also a host name search with host\n"; 
  print "\n\n Example:  ipscan -H 123.123.123.3 -e 12\n";
  exit();
}


($high,$second,$third,$start)=split('\.',$host);

for ($last=$start;$last<=$endipscan;$last++) 
{
	$host=join('.',$high,$second,$third,$last);
	printf ("Looking for %s ..... ",$host);
	$pinging=`fping -a -t $pingto $host`;
	chop($pinging);
	if ($pinging eq '')
	{
		print "Seems unreachable\n";
	}
	else
	{
		print "Seems reachable\n";
	}
	if ($dohost == 1)
	{
		$host=join('.',$last,$third,$second,$high);
		$|=1;
	 	open(HOST,"host -t ptr $host.in-addr.arpa 2>& 1 |");
		while (<HOST>) { print; }
		close (HOST);
		printf("\n");
	}
}

