php PHP上的端口扫描程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php PHP上的端口扫描程序相关的知识,希望对你有一定的参考价值。

<?php
ini_set('max_execution_time', 0);
ini_set('memory_limit', -1);

$host = 'google.com';
$ports = array(21, 25, 80, 81, 110, 143, 443, 587, 2525, 3306);

foreach ($ports as $port)
{
    $connection = @fsockopen($host, $port, $errno, $errstr, 2);

    if (is_resource($connection))
    {
        echo '<h2>' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.</h2>' . "\n";

        fclose($connection);
    }
    else
    {
        echo '<h2>' . $host . ':' . $port . ' is not responding.</h2>' . "\n";
    }
}

以上是关于php PHP上的端口扫描程序的主要内容,如果未能解决你的问题,请参考以下文章