BTalon Posted April 24, 2006 Share Posted April 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8254-querying-server/ Share on other sites More sharing options...
wisewood Posted April 24, 2006 Share Posted April 24, 2006 I'm not sure that PHP would do what it is that you're after to be honest. ActiveX maybe? Would love to know if this is do-able though. Quote Link to comment https://forums.phpfreaks.com/topic/8254-querying-server/#findComment-30106 Share on other sites More sharing options...
Tjk Posted April 24, 2006 Share Posted April 24, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/8254-querying-server/#findComment-30134 Share on other sites More sharing options...
wisewood Posted April 24, 2006 Share Posted April 24, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/8254-querying-server/#findComment-30146 Share on other sites More sharing options...
Tjk Posted April 25, 2006 Share Posted April 25, 2006 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:) Quote Link to comment https://forums.phpfreaks.com/topic/8254-querying-server/#findComment-30708 Share on other sites More sharing options...
BTalon Posted April 25, 2006 Author Share Posted April 25, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8254-querying-server/#findComment-30780 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.