#!/usr/bin/perl5.8.4
require 'config/paths.pl';
require 'perllib/getopts.pl';
Getopts("f:v");
$debug = "";
if ($#ARGV < 0 && ! $opt_f) {
  print "Usage fwping [-v] [-f filename] [ systems]\n";
exit;
}
$FW_TIMEOUT=2;
$STD_PORTS="25 53 80 139 143 445 4000 6000";
$debug = "ON" if $opt_v;
if ($opt_f) {
  if (-f $opt_f) {
    @TARGETS = "";
    $target_cnt = "";
    open(TARGETS, "$opt_f");
    while (<TARGETS>) {
      chomp;
      $TARGETS[$target_cnt++] = $_ if (! /^\#/);
    }
  } else {
    print "File, $opt_f, not found\n";
    exit;
  }
} else {
  @TARGETS = @ARGV;
}
for (@TARGETS) {
  $target = $_;
  $alive  = "";
  $fw     = "";
  open(FWPING, "$TCP_SCAN -a -f 1 $target $STD_PORTS|");
  while (<FWPING>) {
    chomp;
    print "$target: $_\n" if $debug;
    $fw  = "but firewalled";    
    next if /timed/;
    next if /no route/;
    next if /unreachable/;
    $alive="ON";
  }
    print "$target is alive $fw\n" if $alive;
}
close (FWPING);
