Ping CS 服务器

发布于 2024-09-05 15:21:20 字数 230 浏览 7 评论 0原文

这已经困扰我一段时间了,有人可以告诉我如何 ping 反恐精英服务器吗?

我只是想 ping 服务器并看看它是否在线,仅此而已。

我在网上发现了许多使用 fsock 和 UDP 来执行此操作的小片段,但它们实际上都没有完成我想要的工作。

我发现的大多数服务器都将离线服务器显示为在线服务器。

如果有人能为我提供这些有用的信息(代码),我将非常感激。

先谢谢你了^_^

This has been bothering me for awhile, can some one show me how to ping a counter strike server.

I just want to ping the server and see if it is online, thats all.

I found many small snippets online that were using fsock and UDP to do this but none of them actually did the job i wanted it to do.

Most of the ones i found were showing offline servers as online.

I would really really appreciate if some one could provide me with this useful information (code).

Thank you in advance ^_^

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

漆黑的白昼 2024-09-12 15:21:20

你不能只是 ping 服务器,因为它使用 UDP 而不是普通的 TCP,所以为了检查它的状态,你需要“查询”服务器,你可以在这里找到有关可以发送到 CS 服务器的命令的信息:http://developer.valvesoftware.com/wiki/Server_queries#A2A_PING

无论如何,以下代码(PHP ) 可用于检查 CS 服务器状态。

`

`
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_connect($socket, "cs.somesv.com", 27015);

    socket_write($socket, "\xFF\xFF\xFF\xFF\x69");

    if (@socket_read($socket, 5) == "\xFF\xFF\xFF\xFF\x6A") {
        echo '<FONT COLOR=lime>Online</FONT>';
    } else {
        echo '<FONT COLOR=red>Offline</FONT>';
    }

    socket_close($socket);
?>`

呸!这段代码块并不能正常工作! :(

不管怎样,我每天都在我的服务器上使用这个代码,希望它对你有用。

you can't just ping the server since it uses UDP instead of normal TCP, so in order to check it's status you need to "query" the server, you can find information about what command you can send to CS servers here: http://developer.valvesoftware.com/wiki/Server_queries#A2A_PING

Anyway the following code (PHP) can be used to check CS server status.

`

`
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_connect($socket, "cs.somesv.com", 27015);

    socket_write($socket, "\xFF\xFF\xFF\xFF\x69");

    if (@socket_read($socket, 5) == "\xFF\xFF\xFF\xFF\x6A") {
        echo '<FONT COLOR=lime>Online</FONT>';
    } else {
        echo '<FONT COLOR=red>Offline</FONT>';
    }

    socket_close($socket);
?>`

Bah! this code blocks don't really work fine! :(

Anyway, I use this code everyday for my server, hope it works fine for you.

最舍不得你 2024-09-12 15:21:20

我的脑海中有两个选择:

fsockopen

http://www.phptoys.com/e107_plugins/content/content.php?content.41

Net_Ping Pear 包

http://www.codediesel.com/php/ping-a-server-using-php/

使用CS服务器的IP。

Two choices off the top of my head:

fsockopen:

http://www.phptoys.com/e107_plugins/content/content.php?content.41

Net_Ping Pear package:

http://www.codediesel.com/php/ping-a-server-using-php/

Using IP of the CS server.

往日 2024-09-12 15:21:20

获取 ClanManager,它具有检查 CS 服务器状态的模块。

这是包含与 CS 服务器对话的示例的文件,

http://clanmanager.cvs.sourceforge.net/viewvc/clanmanager/ocm/server/counterstrike.inc?revision=1.3&view=markup

Get ClanManager and it has modules to check status of CS server.

This is the file with examples talking with CS servers,

http://clanmanager.cvs.sourceforge.net/viewvc/clanmanager/ocm/server/counterstrike.inc?revision=1.3&view=markup

活雷疯 2024-09-12 15:21:20

您还可以执行所谓的 TCP ping。基本上,您只需连接然后断开连接,无需任何通信。如果连接成功,您就知道服务器已启动,如果连接失败,则服务器已关闭。当我说服务器时,我指的是您感兴趣的程序,而不是物理服务器。

You can also do what's known as a TCP ping. Basically, you just connect then disconnect without any communication. If the connection succeeds, you know the server is up, if it fails it's down. When I say server I mean the program you're interested in, not the physical server.

2024-09-12 15:21:20

这是检查 CS 服务器是否在线的 PHP 函数:

function isCsServerOnline($server, $port = 27015)
{
    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    // timeout 1.5 seconds
    $timeout = array('sec' => 1, 'usec' => 500000);
    socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, $timeout);
    socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $timeout);

    @socket_connect($socket, $server, $port);
    @socket_write($socket, "\xFF\xFF\xFF\xFF\x69");

    $isOnline = @socket_read($socket, 5) == "\xFF\xFF\xFF\xFF\x6A";
    @socket_close($socket);

    return $isOnline;
}

您可以像这样使用它:

$server = 'some.cs.server';
$port = 27015;

$isOnline = isCsServerOnline($server, $port);
echo $isOnline ? 'Online' : 'Offline';

Here is PHP function to check if CS server is online:

function isCsServerOnline($server, $port = 27015)
{
    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    // timeout 1.5 seconds
    $timeout = array('sec' => 1, 'usec' => 500000);
    socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, $timeout);
    socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $timeout);

    @socket_connect($socket, $server, $port);
    @socket_write($socket, "\xFF\xFF\xFF\xFF\x69");

    $isOnline = @socket_read($socket, 5) == "\xFF\xFF\xFF\xFF\x6A";
    @socket_close($socket);

    return $isOnline;
}

You can use it like this:

$server = 'some.cs.server';
$port = 27015;

$isOnline = isCsServerOnline($server, $port);
echo $isOnline ? 'Online' : 'Offline';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文