检查是否可以使用PHP访问端口
我试图检查我的服务器上的端口是否打开,我有一些php来做这件事检查是否可以使用PHP访问端口,php,connection,ports,Php,Connection,Ports,我试图检查我的服务器上的端口是否打开,我有一些php来做这件事 <?php $host = 'xxxxxxxxxxxxxxxxxxx'; $ports = array(xxxxxx); foreach ($ports as $port) { $connection = @fsockopen($host, $port); if (is_resource($connection)) {
<?php
$host = 'xxxxxxxxxxxxxxxxxxx';
$ports = array(xxxxxx);
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";
}
}
?>
其输出如下:
domain.zapto.org:80(http)已打开。
domain.zapto.org:8090不是。
回应。domain.zapto.org:34134没有响应
但是如果我访问domain.zapto.org:34134,它就可以正常工作了。。。。所以它是可以到达的,但为什么它说它不是?有什么想法吗?谢谢大家。通过提供
fsockopen
函数附加参数,为代码添加基本调试(请参阅)
$host='theofilaktoshouse.zapto.org';
$ports=阵列(80809034134);
foreach($port作为$port)
{
$errno=null;
$errstr=null;
$connection=@fsockopen($host、$port、$errno、$errstr);
如果(是_资源($connection)){
回显“.$host.”:“.$port.”(“.getservbyport($port,'tcp'))已打开。“。”\n”;
fclose($连接);
}否则{
echo“{$host}:{$port}没有响应。错误{$errno}:{$errstr}”。“\n”;
}
}
原因它可能不起作用的原因是主人制定的交通规则。他们可以轻松禁止80以外端口的传出连接谢谢您的回复。错误110:连接超时然后通过添加另一个参数,如
@fsockopen($host、$port、$errno、$errstr、$timeout),尝试将设置超时设置为您的情况下合理的时间代码>
$host = 'theofilaktoshouse.zapto.org';
$ports = array(80, 8090, 34134);
foreach ($ports as $port)
{
$errno = null;
$errstr = null;
$connection = @fsockopen($host, $port, $errno, $errstr);
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. Error {$errno}: {$errstr} </h2>" . "\n";
}
}