#!/usr/bin/perl -w

require "common.pl";
#this script takes a list of abone-core-node-copy.txt and 
# finds IP/OS and if we have access permissions.

my $ANETD_BIN = "/usr/home/abocc/anetd/bin";


# foreach $_ (`ping -c3 -q infocom.cmcl.cs.cmu.edu`) { # once per test  line
# $percentloss = /0% packet loss/;
#if ($percentloss == 1) {
#	$pingsuccess = 1;
#}
while ($host = <STDIN>) {
    chop($host);
    $oneline =  "\"$host\"";
#for $_ (`$ANETD_BIN/sc.bsd44 -f anee2 $host QUERY`) {
#$os = "blah";
#($textancors,$acct,$release, $os) = split(/ /);
#print "OS is $os \n";
    
#}
    
    $output = (`ping -c1 -q $host`);
    $getipadd = $output;
    $getipadd =~ /\(\S+\)/;
    $getipadd = substr($&, 1, length($&) - 2);
#print "ipaddress $getipadd \n";
    $oneline = $oneline . ", \"$getipadd\"";
    $lookfor = " 0% packet loss";
    if ($output !~ /$lookfor/) { # if there are packet losses then don't add 
#    print "pktloss: $& on $host \n";
	
    } else {
	
	$thismuch =  (`$ANETD_BIN/sc.bsd44 -f anee2 $host QUERY 2>&1`);
	($textancors,$acct,$release, $os, $everythingelse) = split(/\s/, $thismuch);
#should verify that the os is one of three acceptable ones...in case QUERY fail
#print "thisos is: $os \n";
	$error_msg = "do_tcp: connect:";
	if ($thismuch =~ $error_msg) {
#    print"this much: $thismuch \n";
#    print "AHA! \n";
	} else {
	    $oneline = $oneline . ", \"$os\", \n";
	    print "$oneline";
	}
    }
    
}
