View Full Version : Small Server Query Script
[FBI]_Inque187
06-14-2005, 03:26 AM
I am working on making a small server query script using PHP in order to query the UDP port of the Ventrillo server and return back if the server is online or offline. Here is the script I created from another game server I have running (slightly moddified for ventrilo purposes). I know how to query the UDP port and everything but I need to know what should I send in order for the server to respond if it is up or down.
<?PHP
$vt_ip = "123.45.67.89";
$vt_port = "3784";
$vt_connect = fsockopen("udp://${vt_ip}", $vt_port);
socket_set_timeout($vt_connect, 000002);
if (! $vt_connect) {
echo '<FONT COLOR=#990000><B>SERVER OFFLINE</B></FONT>';
exit;
} else {
}
$send = ???? WHAT GOES HERE ????
fwrite($vt_connect, $send);
$output = fread ($vt_connect, 5);//0);
if (! $output)
echo '<FONT CLASS=f1 COLOR=#DD0000><B>OFFLINE</B></FONT>';
else{
echo '<FONT CLASS=f1 COLOR=#00DD00><B>ONLINE</B></FONT>';
}
fclose($vt_connect);
?>
Before anyone asks or says; I have tried the ventrilo_status.php and apparently it crashes the ventrilo server. I only want a small script to say either "Online" or Offline" - I don't need all that other extra info from the server. Any help would be greatly appreciated.
Patrick
06-14-2005, 05:36 AM
_Inque187']Before anyone asks or says; I have tried the ventrilo_status.php and apparently it crashes the ventrilo server. I only want a small script to say either "Online" or Offline" - I don't need all that other extra info from the server. Any help would be greatly appreciated.
It does not crash the server.
You don't need to do all that, just check to see if you can open a socket to the specified IP/Port and if it responds, echo online, if not, echo offline or whatever else you want to do.
Flagship
06-14-2005, 10:49 AM
You'll need to use the PHP scripts available on the download page.
[FBI]_Inque187
06-14-2005, 01:54 PM
Ok, I run a router and the port is always open so checking the IP/Port will always return true. I need to be able to query the server to see if it is currently running or not. I have other game servers on the same IP but different ports and I have a script that works for them that shows if the server is online or offline.
The reason why I am trying to make a smaller script is because I don't need all that extra info that is included in the ventrilo_status.php tool. I only want to know if the server is offline or online. I can make it work but I need to know what query data should be sent to the server so that it will return if it is online or offline.
The script is simple and very effective if I had the data needed to send to the server. My mission is to make a smaller script that returns a simple answer from the server. I can query the IP all day and it will return "online" if the router is on. But if the router is off then I won't get a return. That is not what I need. I need to be able to see if a server/service application is running on a particular IP.
This is my website http://www.fbi-clan.org/portal.php that has a list of servers running. Notice that the America's Army Game Server and the Shoutcast Radio Server show that they are online. This is what I need.
Nationvoice.com
06-14-2005, 02:18 PM
Just because you have the port open does not mean it the socket will connect. The socket must get a reply in order for it to to be set.
@$output = fsockopen(yourIP, PORT, $errno, $errstr, 2);
if (!$output) {
echo "<font color=\"red\"><blink><strong>Offline</strong></blink></font>";
} else {
echo "<font color=\"green\"><strong>Online</strong></font>";
}
This should work just fine.
[FBI]_Inque187
06-14-2005, 03:21 PM
Ok, I reworked the script with the suggestions and it works now. I guess I was going by what other servers require. This script works fine with Ventrilo (even without the Status settings in the Ventrilo server.ini file). Now, I have to get it to work on my other game servers and Teamspeak server.
<?PHP
$vt_ip = "123.45.67.89";
$vt_port = "3784";
$output = @fsockopen($vt_ip, $vt_port, $errno, $errstr, 2);
socket_set_timeout($output, 000002);
if (!$output) {
echo "<FONT CLASS=f1 COLOR=#DD0000><B>OFFLINE</B></FONT>";
} else {
echo "<FONT CLASS=f1 COLOR=#00DD00><B>ONLINE</B></FONT>";
}
@fclose($output);
?>
Nationvoice.com
06-14-2005, 03:30 PM
_Inque187']
socket_set_timeout($output, 000002);
?>
That is not needed as @fsockopen($vt_ip, $vt_port, $errno, $errstr, 2); already has the timeout time in it (the 2).
I knew this would work becuase this is what we use to do a fast query on our servers to see if their online or offline. I'm pretty sure this will work with game servers but that leaves you alot of room for error. I would just stick with qstat on that.
As far as team speak, from what I have heard it uses udp and not tcp and from what I've been told sockets only use tcp so you might need to find another script to do TS qeuries.
vBulletin® v3.6.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.