【发布时间】:2012-10-03 19:12:28
【问题描述】:
我一直在尝试 ping 特定 IP 和端口以检查它是在线还是离线。如果我将端口设置为 80,它可以工作,但任何其他端口都说它不工作。我可以通过游戏、telnet 等连接到端口
//Connection Info
$ip = "*******"; //IP
$port = "2302"; //Port
//Connection
$sock = @fsockopen( $ip, $port, $num, $error, 2 ); //2 is the ping time, you can sub what you need
//Check Status
if( !$sock ){
//Closed
echo( "It appears to be closed" );
}
if( $sock ){
//Open
echo( "It appears to be open" );
fclose($sock);
}
这是我得到的错误
Warning: fsockopen() [function.fsockopen]: unable to connect to *******:2302 (No connection could be made because the target machine actively refused it. )
【问题讨论】:
-
您是否收到任何错误消息?尝试删除
@以显示任何错误和/或在运行fsockopen后检查$num和$error变量