PHP: a simple script to check a list of active port:host list

<?php
$filename="hosts.txt";
if(!is_file($filename))
{
   echo "$filename not found";
   exit;
}
foreach(file($filename) as $line) {
    $line =trim($line);
    if(strpos($line,":")===false)
        continue;
    list($host,$port)=explode(":",$line);
    $fp = @fsockopen($host, $port, $errno, $errstr, 30);
    $result="GOOD";
    if(!$fp)
    {
        $result="BAD,$errstr($errno)";
    }
    echo  "$line,$result\n";
}

?>

Leave a Reply

Your email address will not be published. Required fields are marked *