#!/s/std/bin/perl

# 
#  getnethostkeys.pl by Michael Blodgett (mblodget@cs.wisc.edu)
#
# 	script runs scanhostkey for various network devices which don't send hostkeys like hosts do
#

use strict;
use CSL::Pg;
use CSL::DBs;
use DBI;

my $scanhostkey_cmd = "/s/krb5/sbin/scanhostkey";

my $dbh = DBI->connect ($CSL::DBs::csdb) or die "Could not connect to database";

$dbh->{HandleError} = sub {die "Problem with database query" };

my $query = $dbh->prepare ("select name from splat.devices where type = 'switch' or type = 'router' or type = 'firewall'");
$query->execute ();

while (my $entry = $query->fetchrow())
  {
	printf("Running entry %s\n",$entry);
        system "$scanhostkey_cmd $entry";
  }
$query->finish;
$dbh->disconnect;
