测试端口是否已打开并使用PHP转发

测试端口是否已打开并使用PHP转发,第1张

测试端口是否已打开并使用PHP转发

我不确定“正确转发”是什么意思,但希望这个例子能解决这个问题:

$host = 'stackoverflow.com';$ports = array(21, 25, 80, 81, 110, 443, 3306);foreach ($ports as $port){    $connection = @fsockopen($host, $port);    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";    }}

输出:

stackoverflow.com:21 is not responding.stackoverflow.com:25 is not responding.stackoverflow.com:80 (http) is open.stackoverflow.com:81 is not responding.stackoverflow.com:110 is not responding.stackoverflow.com:443 is not responding.stackoverflow.com:3306 is not responding.

有关 端口号的完整列表,请参见http://www.iana.org/assignments/port-
numbers



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5487558.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存