Linux technical support - [email protected]


Php tcp port scanner

<?

#!/usr/bin/php -q

sleep(180000);

error_reporting(0);

$errNo;
$errStr;

function checkTcp($ip)
{
if(isset($ip)) {
for($i=1;$i<=65535;$i++) {
$conn = @fsockopen($ip, $i, &$errno, &$errstr, 3);

if ($conn).

{
//echo "Port $i is OPEN on $ip. ";

$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! Port $i is OPEN on $ip. \n";
$from = "[email protected]";
$headers = "From:" . $from;

mail($to,$subject,$message,$headers);

}
else
{
//echo "Port $i is closed on $ip. \n";
}

}
}
}

while(1) {

$handle = @fopen("/var/scripts/scanTcp/ip.txt", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {

checkTcp($buffer);

}
if (!feof($handle)) {
//echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}

}

?>

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>