<?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 © 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 © 2004 Security Angel Team[S4T] All Rights Reserved.</b></TD>
</TR>
</TABLE>
</center>
</body>
</html>