Creating Auto Checker for IP Network Lifetime

Hi! I have a tutorial to check lifetime connectivity for IP and PORT in your Network. You may use it as component of enterpise application to check IP and PORT.
So, what next ???

 

Offcourse, we need this files: ipchecker.php, frame_ip.php, index.php, and jquery framework.
First create ipchecker.php for function handler:
Code:

<?
/**
#
# Auto Checker for IP Network Lifetime
# Author  hairul azami a.k.a dr.emi <webmaster@dremi.info>
# Website http://dremi.info
# License: GPL
#
**/
error_reporting(0);
define("_IMAGES", "images/");
define("_IPROUTER", "192.168.1.1");
function checkIP($ip, $p)
{
//error_reporting(E_ALL);
@set_time_limit(0);
$address = "$ip"; //your public IP
$port = $p; // your IP open port
$fp = @fsockopen($address,$port,$errno,$errstr,10);
stream_set_timeout($fp, 1);
if ($fp)
{
$statusIPport =  "<font color=green>Connected</font>";
$imgTitle = "Connected";
$imgStats = "accepted_32.png";
}
else
{
$statusIPport =  "<font color=#CCCCCC>Disconnect</font>";
$imgTitle = "Disconnect";
$imgStats = "warning_32.png";
}
$info = stream_get_meta_data($fp);
if($info['timed_out'])
{
$statusIPport =  "<font color=#CCCCCC>Time Out</font>";
$imgTitle = "Time Out";
$imgStats = "cancel_32.png";
}
flush();
$checkID = strtoupper(gethostbyaddr($address));
if($checkID != $address)
{
$comname = $checkID;
}
elseif($checkID == _IPROUTER)
{
$comname = "ROUTER";
}
else
{
$comname = "NONAME";
}
echo "
<div style='text-align:center;'>
<img src='"._IMAGES . $imgStats."' alt='$imgTitle' title='$imgTitle' border=0><br>
<strong>$imgTitle</strong><br>
$address:$port<br>
$comname
</dvi>";
}
checkIP($_GET['ip'], $_GET['port']);
?>

The function will used as checker for each of variable IP and PORT
Second, create an jQuery Auto Load for file, called as frame_ip.php
In this file, you must load jQuery framework to complete javascript function bellow
Code:

<script language="javascript" src="jquery-1.2.6.min.js"></script>
<script language="javascript">
//show animation
$(function(){
$("#ajax_display").ajaxStart(function(){
$(this).html('<div style="text-align:center"><img src="images/ajax-loader-trans.gif"/><br>Checking Target...</div>');
});
$("#ajax_display").ajaxSuccess(function(){
$(this).html('');
});
$("#ajax_display").ajaxError(function(url){
alert('jqSajax is error ');
});
});
</script>

Then to load ipchecker.php, I use this code:

<div id="ajax_display"></div>
<script type="text/javascript">
function getRandom() {
$("#random").hide("slow");
$("#random").load("ipchecker.php?ip=<? echo $_GET['ip']; ?>&port=<? echo $_GET['port']; ?>", '', callback);
}
function callback() {
$("#random").show("slow");
setTimeout("getRandom();", 10000*2);
}
$(document).ready(getRandom);
</script>
<div id="random"></div>

While ip and port was defined in iframe URL, PHP function checkIP($ip, $p) will work.
I use this line for set the time while load ipchecker.php from first time to next load progress.

setTimeout("getRandom();", 10000*2);

The last is index.php
This file will give you GUI of all process

<?
for($i=1;$i<=10;$i++)
{
?>
<div id="ipslot">
<iframe scrolling="No" frameborder="0" class="frameloader" width="100px" height="100px" name="ajax_ipchecker" src="frame_ip.php?ip=192.168.1.<? echo $i; ?>&port=80">
</iframe>
</div>
<?
}
?>

While index.php loaded, frame_ip.php will work as “data sender” from URL, so we can check it in checkIP function.
Well this is screenshoot while you access index.php from http://localhost/[foldername]/index.php

OK, I think it’s really good time to see you here, thanks for read 🙂
If you find any bug / report, just comment here ..

4 thoughts on “Creating Auto Checker for IP Network Lifetime”

Leave a Reply

Your email address will not be published. Required fields are marked *