我一直在尝试 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. )