Jump to content

Querying server


BTalon

Recommended Posts

ive searched the forums and didnt find anything like this, so hopefully im not double posting.

my question is, i want to query a program like say teamspeak or IRC to see if it is running or if it is not running, and have it send back a true or false. kinda like what ftp_exec would do. but im not having any luck with that. there are about 4 different programs running on the server that i want to be able to check and see if they are running. kinda like a green light for yes and a red light for no situation. im not new to php and i know this is possible im just not finding the right function. any ideas would be greatly appreciated.
Link to comment
Share on other sites

I'm also interested in something like this. I was wondering if something like Sockets could be used to check if a server is online or not? Would this be possible?

EDIT: Specifically looking at something like this:

[a href=\"http://uk.php.net/manual/en/function.socket-connect.php\" target=\"_blank\"]http://uk.php.net/manual/en/function.socket-connect.php[/a]
Link to comment
Share on other sites

I just modified a script that i found on the php.net documentation pages.

I've just kinda thrown my own bits of code at it, so its not very tidy, but it works.

Run that script, and enter a domain (ie phpfreaks.com) or IP address into the text box and hit submit. If its active, it returns the time taken... if not, it returns Not Online.

PS. I have tested this with IP and domains i know are both active and inactive. It does work.

[code]
<?php    session_start();

if(!$_POST[address]) { echo "<form method=post action=$PHP_SELF>Address: <input type=text name=address><input type=submit value=Submit></form>";}
else {
    // Checksum calculation function
    function icmpChecksum($data)
    {
    if (strlen($data)%2)
    $data .= "\x00";
    
    $bit = unpack('n*', $data);
    $sum = array_sum($bit);
    
    while ($sum >> 16)
    $sum = ($sum >> 16) + ($sum & 0xffff);
    
    return pack('n*', ~$sum);
    }
    // Making the package
    $type= "\x08";
    $code= "\x00";
    $checksum= "\x00\x00";
    $identifier = "\x00\x00";
    $seqNumber = "\x00\x00";
    $data= "Scarface";
    $package = $type.$code.$checksum.$identifier.$seqNumber.$data;
    $checksum = icmpChecksum($package); // Calculate the checksum
    $package = $type.$code.$checksum.$identifier.$seqNumber.$data;
    // And off to the sockets
    $socket = socket_create(AF_INET, SOCK_RAW, 1);
    if(!@socket_connect($socket, "$_POST[address]", null)){echo "<b>wisewood says: Not Online.</b>";}
    // If you're using below PHP 5, see the manual for the microtime_float
    // function. Instead of just using the m
    //     icrotime() function.
    $startTime = microtime(true);
    @socket_send($socket, $package, strLen($package), 0);
    if (@socket_read($socket, 255)) {
    echo round(microtime(true) - $startTime, 4) .' seconds';
    }
    socket_close($socket);
}
    ?>
[/code]
Link to comment
Share on other sites

I like to know what I'm using. :) I was wondering if you could explain a few things to me...

Firstly the function icmpChecksum. Could you run through how it works with me? And secondly how can I create my own package IE if i wanted to make $data= "ping" etc etc (any articles I could look at to improve my understanding in explaining what each part of the package is)?

The bottom half of the script (dealing with the sockets) I understand but I'm a little lost on the actual creation of the package.

Help appreciated as always,

Regards

:)
Link to comment
Share on other sites

Thx wisewood. i will spend some time playing with that code.

more specifically let me tell you what i need this for so maybe it will give you more ideas.

i have the server, so everything on it is mine to start and stop. its a linux server. on it i have a website, TS2, irc. all running. i have ftp access, so its not a probelm getting permission on and off the server. i just want to put a panel on my website showing if ts2 and irc are currently up and running or if they are turned off. i always thought that since i could actually put a file right on the server it would just be a matter of creating a fake login script and if the login is successful, then it would submit back a true. and if the login failed it would return false. but im not sure how to create a fake lgin that will log out once its submitted back true or false.

im not sure what i just said makes sense, im sure it probably confused everyone more. but again i will play with the script and see if maybe i can put in a INPUT type hidden with the ip of the irc and ts2 and maybe it will come back for each one. thx for the help so far though, i do appreciate it.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.