我的两分钱......(由于多行文本要求,在循环中添加文本)
<?php
error_reporting(E_ALL);
error_reporting(-1);
ini_set('error_reporting', E_ALL);
/*
construction of the tcp scan
I would prefer building a C C.G.I.
but let's experiment with php
(apache user rights over nmap resources)
no php ressources on google website,
noor ajax call (worker) other then 'self'
so
I will use a php trick into the <img> html tag.
(<img src="mysite.com/gdtrick.php">)
I'm wondering if I can do the same with, let's say,
gdtrick.cgi... that would be so cool.
*/
// size of the image to create
$x = 300;
$y = 300;
$displacement_y = 24;
//debug
//$zetext = "test";
$image = imagecreate($x,$y);
$white = imagecolorallocate($image, 255,255,255);
$black = imagecolorallocate($image, 0,0,0);
$zeipaddr = "";
$zetext = "";
function getUserIP() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
$zeipaddr = getUserIP();
//for debug
//echo "IP: " .$zeipaddr."<br>\n";
//$zeipaddr = "192.168.1.18";
$ports = array(21, 22, 23, 80, 8080, 8081, 8082, 5900, 5901, 5902, 3306, 6000, 6001, 6002, 6003);
//$ports = array(80);
$text1 = imagettftext($image, 12, 0, 12, $displacement_y, $black, "/usr/share/fonts/truetype/freefont/FreeSans.ttf", "PHP SCAN ON DEMAND");
$displacement_y += 12;
foreach ($ports as $port)
{
$connection = @fsockopen($zeipadrr, $port, $errno, $errstr, 1);
if (is_resource($connection))
{
$zetext = $zeipadrr . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.' ;
$text1 = imagettftext($image, 10, 0, 6, $displacement_y, $black, "/usr/share/fonts/truetype/freefont/FreeSans.ttf", $zetext);
fclose($connection);
}
else
{
$zetext = $zeipaddr . ':' . $port . " not active." ;
$text1 = imagettftext($image, 10, 0, 6, $displacement_y, $black, "/usr/share/fonts/truetype/freefont/FreeSans.ttf", $zetext);
}
$displacement_y += 16;
}
$displacement_y += 12;
$text1 = imagettftext($image, 12, 0, 12, $displacement_y, $black, "/usr/share/fonts/truetype/freefont/FreeSans.ttf", "Port scanning done !!!");
header('Content-Type: image/jpeg');
imagejpeg($image);
?>