#!/usr/bin/perl

use strict;

my $host = shift;

my $mypath = '/home/jkelly/public_html/development/perl/scandiff';

my $hostscan    = "$mypath/$host";

my $new = 0;
$new = 1 unless open(LASTSCAN, '<', $hostscan);

my @last;
my @current;

if ($new eq 1) {
  open(CURRENTSCAN, '>', $hostscan) || die "cannot open $hostscan: $!\n";
} else {
  @last = <LASTSCAN>;
};

my $foo = `nmap -oG $hostscan $host`;

if ($new eq 0) {
  open(CURRENTSCAN, '<', $hostscan) || die "cannot open $hostscan: $!\n";
  @current = <CURRENTSCAN>;
  unless ($current[1] eq $last[1]) {
    print "DANGER WILL ROBINSON!\n";
    print "current scan:\n$current[1]\nlast scan:\n$last[1]";
  }
}


# Scandiff, version 0.1, Copyright (C) 2007  Joey Kelly, http://joeykelly.net
#
# Scandiff uses Perl and nmap to do a quick-and-dirty sanity check of a particular host, via portscanning.
#
# Usage: perl scandiff.pl 127.0.0.1
#
# Note: you'll need to change $mypath to the directory in which you place this script.
# It is recommended that you mkdir a new directory, so that the portscans are stored in one place.
#
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

