Important alert: (current site time 7/15/2013 10:46:19 AM EDT)
 

VB icon

^!!~ Check if a service/machine is alive ~!!^

Email
Submitted on: 5/5/2004 2:54:06 AM
By: fritz0x00  
Level: Advanced
User Rating: By 6 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 13535
author picture
(About the author)
 
     Check and see if a service is up or down on a certain machine. Useful for alot of things, say you have MSN Messenger or AIM, you can have a script check YOUR IP address and the MSN or AIM port number and then let the users at your website know if your online or not! Can also be useful if you use alot of file mirrors for your website and want to check if there up or down. Infinite amount of uses! Really fun, simple, easy to use, and useful for many things. Well commented.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: ^!!~ Check if a service/machine is alive ~!!^
// Description:Check and see if a service is up or down on a certain machine.
Useful for alot of things, say you have MSN Messenger or AIM, you can have a script check YOUR IP address and the MSN or AIM port number and then let the users at your website know if your online or not! Can also be useful if you use alot of file mirrors for your website and want to check if there up or down. Infinite amount of uses! Really fun, simple, easy to use, and useful for many things. Well commented.
// By: fritz0x00
//
// Inputs:$address, $service
//
// Assumes:Don't forget to change $address and $service, doh!
//
// Side Effects:If you forget to turn off error reporting(error_reporting(0);), you will get a 'Warning' if fsockopen fails to connect.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1354&lngWId=8//for details.//**************************************

<?php
error_reporting(0); //** Turn error reporting off so we don't get the unneeded warning message if we fail to connect, we will handle that our selfs
$address = "127.0.0.1"; //** Address of the machine
$service = 80; //** Service or Port number, in this case 80 for the HTTPD daemon... say we want to have a page to check if our webserver is up
//** fsockopen returns a boolean value upon execution, depending if it fails(returns FALSE or NULL) or not(returns TRUE)
if(fsockopen($address, $service)) //** If we can connect...
{
 //** Address is up, do what you want here
 echo "$address:$service is up!";
}
else //** We can't connect!
{
 //** Address is NOT up, do what you want here
 echo "$address:$service is NOT up!";
}
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

5/18/2004 8:03:38 PM

Very nice, 5 globes from me.
(If this comment was disrespectful, please report it.)

 
5/18/2004 8:04:27 PM

You should change "advance" to something lower... :/
(If this comment was disrespectful, please report it.)

 
5/19/2004 3:08:44 PMZak Farrington

I may have a higher level comprehension of PHP, but that does not keep me from posting simple code snippets that can help alot of people
(If this comment was disrespectful, please report it.)

 
5/28/2004 4:45:29 AM

I want display wheather my yahoo messenger is up or not. Not sure what to write $service= ? Pls help

(If this comment was disrespectful, please report it.)

 
5/31/2005 6:10:19 AM

21 = FTP
23 = Telnet
25 = Mail server
79 = finger
80 = http (web server)
110 = pop3 mail
139= net bios
143 = impa
443 = https

(If this comment was disrespectful, please report it.)

 
5/31/2005 6:12:52 AM

MSN uses port 569 to access: gateway.moswest.msn.net
(If this comment was disrespectful, please report it.)

 
7/7/2005 9:16:20 AMPatabugen-

thanks for the code =]
i was under the impression that "level" was the level of the code and not the user, it would make alot more sense that way anyway.
(If this comment was disrespectful, please report it.)

 
9/8/2005 9:02:51 AMCal

very good code 5globes from me

(If this comment was disrespectful, please report it.)

 
1/13/2006 4:35:08 PMLawrence Cherone

lol. i was just about to write summing like this for my site. you saved me time thanx. great code 5* 4 u.

(If this comment was disrespectful, please report it.)

 
10/13/2006 2:30:24 AMJulius

Hey! good work -- can you get the one which can by the firewall in the remote system?
Julius
(If this comment was disrespectful, please report it.)

 
11/8/2006 10:56:17 PMmatthewtheexploit

hey this is awesome nice work, do you think you could make an html form, where you put the ip and the port, than it checks if its alive, it would be great to add to this :)
(If this comment was disrespectful, please report it.)

 
2/6/2007 9:38:44 PMRPG MAKER

if(@fsockopen($address, $service))

would not show any warning or error messages so that error_reporting(0); is not needed.
(If this comment was disrespectful, please report it.)

 
4/27/2007 10:04:09 PMthe right one

yahoo = 5050
(If this comment was disrespectful, please report it.)

 
11/15/2007 8:27:58 AMwawan

very nice idea thanks guys
(If this comment was disrespectful, please report it.)

 
1/23/2008 6:55:34 PMAric Holland

Thanks. Code worked great for me, helped me detect servers i made in C++ for my clients to get the status off. A temporary script such as this will do , untill i work something better.

Much appreciation. 4 Globes
(If this comment was disrespectful, please report it.)

 
4/21/2009 10:15:48 AMcys

good performance guys.

(If this comment was disrespectful, please report it.)

 
11/4/2011 5:17:28 AMDAVID ELIJAH

How can download this
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.