找回密码
 注册
广告投放 虚位以待【阿里云】2核2G云新老同享 99元/年,续费同价做网站就用糖果主机-sugarhosts.comJtti.com-新加坡服务器,美国服务器,香港服务器
查看: 421|回复: 1

一个简单的php在线端口扫描器

[复制链接]
发表于 2006 年 4 月 20 日 18:02:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
  1. <?php

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

  5. $youip=$HTTP_SERVER_VARS["REMOTE_ADDR"];        // 获取本机IP地址
  6. $remoteip=$HTTP_POST_VARS['remoteip'];            // 获取表单提交的IP地址
  7. ?>
  8. <html>
  9. <head>
  10. <title>安全天使——端口在线检测</title>
  11. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  12. <style TYPE="text/css">
  13. <!--
  14. BODY {   FONT-SIZE: 12px; FONT-FAMILY: Verdana;color:#000000;
  15. }
  16. TD {
  17.     FONT-SIZE: 12px;
  18.     FONT-FAMILY: Verdana;
  19.     color:#000000;
  20.     line-height: 14px;
  21. }
  22. .style1 {color: #FFFFFF}
  23. -->
  24. </style>
  25. </head>
  26. <body>
  27. <center>
  28. <?php
  29. if (!empty($remoteip)){
  30. // 如果表单不为空就进入IP地址格式的判断

  31. function err() {
  32.         die("对不起,该IP地址不合法<p><a href=javascript:history.back(1)>点击这里返回</a>");
  33. }
  34. // 定义提交错误IP的提示信息

  35. $ips=explode(".",$remoteip);
  36. // 用.分割IP地址

  37. if (intval($ips[0])<1 or intval($ips[0])>255 or intval($ips[3])<1 or intval($ips[3]>255)) err();
  38. // 如果第一段和最后一段IP的数字小于1或者大于255,则提示出错

  39. if (intval($ips[1])<0 or intval($ips[1])>255 or intval($ips[2])<0 or intval($ips[2]>255)) err();
  40. // 如果第二段和第三段IP的数字小于0或者大于255,则提示出错

  41. $closed='此端口目前处于关闭状态。';
  42. $opened='<font color=red>此端口目前处于打开状态!</font>';
  43. $close="关闭";
  44. $open="<font color=red>打开</font>";
  45. $port=array(21,23,25,79,80,110,135,137,138,139,143,443,445,1433,3306,3389);
  46. $msg=array(
  47. 'Ftp',
  48. 'Telnet',
  49. 'Smtp',
  50. 'Finger',
  51. 'Http',
  52. 'Pop3',
  53. 'Location Service',
  54. 'Netbios-NS',
  55. 'Netbios-DGM',
  56. 'Netbios-SSN',
  57. 'IMAP',
  58. 'Https',
  59. 'Microsoft-DS',
  60. 'MSSQL',
  61. 'MYSQL',
  62. 'Terminal Services'
  63. );     
  64. // 通过IP格式的检查后用数组定义各端口对应的服务名称及状态

  65. echo "<table  border=0 cellpadding=15 cellspacing=0>\n";
  66. echo "<tr>\n";
  67. echo "<td align=center><strong>您扫描的IP:<font
  68. color=red>".$remoteip."</font></strong></td>\n";
  69. echo "</tr>\n";
  70. echo "</table>\n";
  71. echo "<table cellpadding=5 cellspacing=1 bgcolor=#636194>\n";
  72. echo "<tr bgcolor=#7371A5 align=center>\n";
  73. echo "<td><span class=style1>端口</span></td>\n";
  74. echo "<td><span class=style1>服务</span></td>\n";
  75. echo "<td><span class=style1>检测结果</span></td>\n";
  76. echo "<td><span class=style1>描述</span></td>\n";
  77. echo "</tr>\n";
  78. // 输出显示的表格

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

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

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

  118. ?>

  119. <TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
  120.   <TR>
  121.      <TD align=center><b>Copyright &copy; 2004 Security Angel Team[S4T] All Rights Reserved.</b></TD>
  122.   </TR>
  123. </TABLE>
  124. </center>
  125. </body>
  126. </html>
复制代码

评分

参与人数 1兑换券 +3 收起 理由
winsock + 3

查看全部评分

Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
发表于 2006 年 4 月 20 日 19:38:40 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
看不懂PHP.ASP的还可以看的出一点点.
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2025 年 2 月 2 日 14:05 , Processed in 0.018198 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表