PHP端口扫描
这可能是一个重复的帖子,但我没有看到任何正确解决这个问题的答案.
我正在尝试找到一个可以正确确定TCP或UDP端口状态的php脚本. 我已经尝试了几个我在网上找到的并且它们都返回了错误的结果. 如果我通过http://www.ipfingerprints.com/portscan.php或GRC Shields Up运行测试,则返回正确的结果,但我尝试过的所有PHP脚本都失败并显示端口已关闭. 我通过我的托管帐户运行php脚本,并尝试扫描和测试我自己的网络. 这是我尝试过的脚本之一: <html> <head> <?php echo "<title>Port Scanning " . $_GET['host'] . "</title>"; ?> </head> <body> <?php ini_set('display_errors',0); if(isset($_GET['host']) == true) $host = $_GET['host']; else { echo "You didn't set the host parameter"; die(); } if(isset($_GET['sport']) == true) $sport = $_GET['sport']; else { echo "You didn't set the sport parameter"; die(); } if(isset($_GET['eport']) == true) $eport = $_GET['eport']; else { echo "You didn't set the eport parameter"; die(); } if($sport > $eport) { $sport = $eport; } $scanned = 0; $openports = 0; $maxports = 1; $totalports = ($eport - $sport) + 1; $mins = floor(($totalports / 10) / 60); $secs = ($totalports / 10) - $mins * 60; echo "<font color="blue">Scanning " . $totalports . " ports on " . $host . ",this should take around " . $mins . " minute(s) and " . $secs . " second(s),probably more depending on local website load,hardware,and other factors.<br/><br/></font>"; flush(); do { if($scanned >= $maxports && $maxports != 0) { echo "<font color="darkgreen" size="4">Scan limit of " . $maxports . " ports reached,scanning stopped.</font><br/><br/><font color="darkred" size="4">Scanner written by Samo502</font>"; flush(); die(); } if(fsockopen($host,$sport,$errorno,$errorstr,0.1)) { echo "<font color="darkgreen">Port " . $sport . " is open on " . $host . "</font><br/>"; $openports++; flush(); } else { echo "<font color="red">Port " . $sport . " is not open on " . $host . "</font><br/>"; flush(); } $scanned++; $sport++; } while($sport <= $eport); echo "<br/><font color="blue">Done," . $openports . " out of " . $totalports . " ports are open.</font><br/><br/><br/><font color="darkred" size="4">Scanner written by Samo502</font>"; die(); ?> </body> </html> 有没有人知道如何正确地做到这一点? 谢谢 **更新** http://resources.infosecinstitute.com/php-build-your-own-mini-port-scanner-2/ 任何帮助感激不尽.谢谢 解决方法
最好的解决方案是在PHP中为nmap编写一个包装器 – 严重的是,你不能重新编码比nmap更好的portscan.
如果你真的想这样做,你不应该只是打开TCP端口并检查它是否连接,你应该从较低级别的套接字,原始套接字开始. $mysocket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); 这允许您调查SYN,ACK握手标志并进行隐身或简单快速扫描. 您可以并行创建(非阻塞)套接字并使用socket_select();检查它们的缓冲区/连接,这是在PHP中处理多个套接字的最快和最可靠的方法.我可能会使用分叉或线程或调度部分代码来在单端口扫描的同时运行完整的端口扫描. 您要使用的其他函数是socket_set_timeout()和socket_set_blocking(). shell_exec not working with nmap command https://unix.stackexchange.com/questions/28732/fastest-way-to-port-scan-nmap http://phpnmap.sourceforge.net/ 可能是最好的解决方案,PEAR包nmap包装器:http://pear.php.net/package/Net_Nmap/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |