天天看点

端口扫描php,php-批量端口扫描

phpwebshell端口扫描

header('Content-Type: text/html; charset=utf-8');

error_reporting(0);

print<<

ip:

port:

END;

$timeout=3;

function is_ip($gonten){

$ip=explode(".",$gonten);

for($i=0;$i

{

if($ip[$i]>255){

return(0);

}

}

return ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$",$gonten,$regs);

}

function get_ip_start($ip){

$num = explode('.',$ip);

return array_pop($num);

}

function get_ip_pre($ip){

$num = explode('.',$ip);

return $num[0].".".$num[1].".".$num[2].".";

}

function host_scan($ip,$timeout){

//貌似这样判断主机是否存活不行啊,所以先这样吧。

$fp = fsockopen($ip,-1,$errno,$errstr,$timeout);

if($fp)

return 1;

else

return 1;

fclose($fp);

}

function port_scan($ip,$port,$timeout){

[email protected]($ip,$port,$errno,$errstr,$timeout);

if($fp)

return 1;

else

return 0;

fclose($fp);

}

if(!empty($_POST['ip']) && !empty($_POST['port'])){

$ports = explode(',',trim($_POST['port']));

$ips = trim($_POST['ip']);

$array_ip = explode('-',$ips);

if(!is_ip($array_ip[0])){

echo "Please enter the IP address of the correct format";

}else{

$ip_end = $array_ip[1];

$ip_start = get_ip_start($array_ip[0]);

if($ip_end > 255 or $ip_end < $ip_start)

echo "Please enter the IP address of the correct format";

else{

$ip_pre = get_ip_pre($array_ip[0]);

for($n=$ip_start; $n<=$ip_end; $n++){

$ip = $ip_pre."$n";

if(!host_scan($ip,$timeout)){

echo "the host $ip may be shutdown.

";

ob_flush();

flush();

}

else{

echo "port scan for $ip

";

ob_flush();

flush();

foreach($ports as $port){

if(port_scan($ip,$port,$errno,$errstr,$timeout))

echo "$port --> open

";

else

echo "$port --> close

";

ob_flush();

flush();

}

}

}

}

}

}

?>

端口扫描php,php-批量端口扫描