這可能是一個重複的帖子,但我沒有看到任何正確解決此問題的答案。PHP端口掃描
我試圖找到一個php腳本,可以正確地確定一個TCP或UDP端口的狀態。
我試過幾個我在網上找到的,他們都返回錯誤的結果。 EG:在我的本地網絡上,我有端口5000 UDP & 5060 TCP/UDP打開並正確路由。
如果我通過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>
有誰知道的方法來正確地做到這一點?
感謝
**更新** 我發現這裏面似乎工作好一點,但它仍然沒有檢測到端口21是我目前網絡上開..
http://resources.infosecinstitute.com/php-build-your-own-mini-port-scanner-2/
任何幫助感激地收到。由於
你肯定有沒有你的主機阻止你進行出站連接上的東西嗎?某些託管會阻止PHP進行連接,或者需要使用代理。您的腳本的(限制!)版本是否可以在您的本地計算機上運行,以告訴您Google是否已將端口80打開?另外,超時的十分之一秒可能會有點低 - 如果增加連接超時會發生什麼? –
看起來像我的主機阻止,除非要求打開它們。 我正在嘗試新的腳本,似乎更好,但仍然不是100% – Rocket