当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP端口扫描器

PHP
《PHP设计模式介绍》第十三章 适配器模式
《PHP设计模式介绍》第十四章 动态记录模式
《PHP设计模式介绍》第十五章 表数据网关模式
《PHP设计模式介绍》第十六章 数据映射模式
《PHP设计模式介绍》第十七章 MVC 模式
Zend Framework 入门——快速上手
Zend Framework 入门——多国语言支持
Zend Framework 入门——错误处理
Zend Framework 入门——页面布局
详细介绍php5编程中的异常处理
PHP5 OOP编程中的代理与异常
PHP程序的常见漏洞攻击分析
PHP.MVC的模板标签系统
PHP教程:PHP编码书写规范
PHP开发大型项目的方法:OOP思想
php使用curl模拟用户登陆
php对gb编码动态转utf-8编码的几种方法评测
php设计模式介绍之章代理模式
“在phpMyAdmin使用用户口令登陆”补充
PHP入门速成

PHP端口扫描器


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 62 ::
收藏到网摘: n/a

<?php

//Codz by angel
//Welcome to My Website
//http://www.4ngel.net

$youip=$HTTP_SERVER_VARS["REMOTE_ADDR"];         // 获取本机IP地址
$remoteip=$HTTP_POST_VARS['remoteip'];             // 获取表单提交的IP地址
?>
<html>
<head>
<title>安全天使——端口在线检测</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style TYPE="text/css">
<!--
BODY {   FONT-SIZE: 12px; FONT-FAMILY: Verdana;color:#000000;
}
TD {
     FONT-SIZE: 12px;
     FONT-FAMILY: Verdana;
     color:#000000;
     line-height: 14px;
}
.style1 {color: #FFFFFF}
-->
</style>
</head>
<body>
<center>
<?php
if (!empty($remoteip)){
// 如果表单不为空就进入IP地址格式的判断

function err() {
         die("对不起,该IP地址不合法<p><a href=javascript:history.back(1)>点击这里返回</a>");
}
// 定义提交错误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='<font color=red>此端口目前处于打开状态!</font>';
$close="关闭";
$open="<font color=red>打开</font>";
$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 "<table   border=0 cellpadding=15 cellspacing=0>\n";
echo "<tr>\n";
echo "<td align=center><strong>您扫描的IP:<font
color=red>".$remoteip."</font></strong></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table cellpadding=5 cellspacing=1 bgcolor=#636194>\n";
echo "<tr bgcolor=#7371A5 align=center>\n";
echo "<td><span class=style1>端口</span></td>\n";
echo "<td><span class=style1>服务</span></td>\n";
echo "<td><span class=style1>检测结果</span></td>\n";
echo "<td><span class=style1>描述</span></td>\n";
echo "</tr>\n";
// 输出显示的表格

for($i=0;$i<sizeof($port);$i++)
{
$fp = @fsockopen($remoteip, $port[$i], &$errno, &$errstr, 1);
   if (!$fp) {
     echo "<tr bgcolor=#FFFFFF><td align=center>".$port[$i]."</td><td>".$msg[$i]."</td><td
align=center>".$close."</td><td>".$closed."</td></tr>\n";
   } else {
     echo "<tr bgcolor=#F4F7F9><td align=center>".$port[$i]."</td><td>".$msg[$i]."</td><td
align=center>".$open."</td><td>".$opened."</td></tr>";
   }
}
// 用for语句,分别用fsockopen函数连接远程主机的相关端口,并输出结果

echo "<tr><td colspan=4 align=center>\n";
echo "<a href=portscan.php><font color=#FFFFFF>继续扫描>>></font></a></td>\n";
echo "</tr\n";
echo "</table>\n";
echo "<TABLE cellSpacing=0 cellPadding=10 width=100% border=0>\n";
echo "<TR>\n";
echo "<TD align=center><b>Copyright &copy; 2004 Security Angel Team[S4T] All Rights Reserved.</b></TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</center>\n";
echo "</body>\n";
echo "</html>\n";
exit;
}
// 探测结束

echo "<table   border=0 cellpadding=15 cellspacing=0>\n";
echo "<tr>\n";
echo "<td align=center><strong>您的IP:<font color=red>".$youip."</font></strong></td>\n";
echo "</tr>\n";
echo "<form method=POST action=portscan.php>\n";
echo "<tr><td>\n";
echo "<input type=text name=remoteip size=12>\n";
echo "<input type=submit value=扫描 name=scan>\n";
echo "</td></tr>\n";
echo "</form>";
echo "</table>\n";
// 如果表单为空则显示提交IP地址的表单

?>

<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
   <TR>
     <TD align=center><b>Copyright &copy; 2004 Security Angel Team[S4T] All Rights Reserved.</b></TD>
   </TR>
</TABLE>
</center>
</body>
</html>