0

php 怎样实现nc -v 的检查某个端口开放的功能?

celeste created at6 years ago view count: 2414
report
回复
0
function checkPortOpen($host, $port = 80) {
    $host = preg_replace('/https*:\/\//ism', '', $host);
    if (strpos($host, ':') !== false) {
        $hosts = explode(":", $host);
        $host = $hosts[0];
        $port = $hosts[1];
    }
    $connection = @fsockopen($host, $port, $errno, $errstr, 3);
    if (is_resource($connection)) {
        return true;
    }
    return false;
}
var_export(checkPortOpen('http://www.baidu.com', 80));
6 years ago 回复

相关搜索关键词