php实现在线端口扫描实例代码_PHP教程
时间:2021-07-01 10:21:17
帮助过:92人阅读
$youip=$HTTP_SERVER_VARS["REMOTE_ADDR"];
$remoteip=$HTTP_POST_VARS[remoteip];
?>- php实现端口在线检测
if (!empty($remoteip)){
function err() {
die(" 对不起,该IP地址不合法点击这里返回");
}
// 定义提交错误IP的提示信息
$ips=explode(".",$remoteip);
// 用.分割IP地址
if (intval($ips[0])<1 or intval($ips[0])>255 or intval($ips[3])<1 or intval($ips[3]>255)) err();
// 如果第一段和最后一段IP的数字小于1或者大于255,则提示出错
if (intval($ips[1])<0 or intval($ips[1])>255 or intval($ips[2])<0 or intval($ips[2]>255)) err();
// 如果第二段和第三段IP的数字小于0或者大于255,则提示出错
$closed=此端口目前处于关闭状态。;
$opened=此端口目前处于打开状态!;
$close="关闭";
$open="打开";
$port=array(21,23,25,79,80,110,135,137,138,139,143,443,445,1433,3306,3389);
$msg=array(Ftp,Telnet,Smtp,Finger,Http,Pop3,Location Service,Netbios-NS,Netbios-DGM,Netbios-SSN,IMAP,Https,Microsoft-DS,MSSQL,MYSQL,Terminal Services);
// 通过IP格式的检查后用数组定义各端口对应的服务名称及状态
echo "
";
echo "
";
echo "您扫描的IP:".$remoteip." |
";
echo "
";
echo "
";
echo "
";
echo "
";
echo "端口 |
";
echo "服务 |
";
echo "检测结果 |
";
echo "描述 |
";
echo "
";
// 输出显示的表格
for($i=0;$i
{
$fp = @fsockopen($remoteip, $port[$i], &$errno, &$errstr, 1);
if (!$fp) {
echo "".$port[$i]." | ".$msg[$i]." | ".$close." | ".$closed." |
";
} else {
echo "".$port[$i]." | ".$msg[$i]." | ".$open." | ".$opened." |
";
}
}
// 用for语句,分别用fsockopen函数连接远程主机的相关端口,并输出结果
echo "
"; echo "继续扫描>>> |
";
echo "
echo "
";
echo "
";
echo "
";
echo "端口扫描 |
";
echo "
";
echo "
";
echo "
";
echo "
";
echo "
";
exit;
http://www.bkjia.com/PHPjc/486202.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486202.htmlTechArticle?php $youip=$HTTP_SERVER_VARS["REMOTE_ADDR"]; $remoteip=$HTTP_POST_VARS[remoteip]; ? html head titlephp实现端口在线检测/title meta http-equiv="Content-Type" content="text/h...