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

phpwebshell端口扫描

/*

auth: eT48

blog: http://blog.csdn.net/et48_sec

*/

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){

$fp=@fsockopen($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();

}

}

}

}

}

}

?>

0818b9ca8b590ca3270a3433284dd417.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值