Creating Auto Checker for IP Network Lifetime

June 27th, 2009 by dr.emi

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 ..

Popularity: 22% [?]

Download Demo Unavailable
Bookmark Subscribe
Hello my fox! Glad to see you today!

If you love my tutorial, please chose any action from the left button.

11 Comments

fajar Said:  

dok..ini bisa client server ga ? kek winsock gt..

cokky Said:  

thanks..

dr.emi Said:  

@fajar

bisa donk :)

pututik Said:  

wah mantap nih, ijin unduh dan pelajari step by step ya mas

David Said:  

Dear Mas Dremi,

Demo-nya sudah saya coba dan mantaf.

Tapi ada beberapa IP address yang unavailable padahal PC tersebut dengan IP yang sama dalam keadaan connected. Bisa di bantu mas?

Oya ada masukan nih mas, kalau bisa set IP-nya jgn dibikin random bisa gak ?
Contoh Saya hanya ingin menampilkan IP berdasarkan department masing-masing.

Thank You.

dr.emi Said:  

@david
terimakasih. jika ip yang dicek menggunakan port, cek ketersediaan portnya. misal jika port 80, maka ip tersebut memiliki web servis, biasanya apache. cek web servis, apakah sudah berjalan dengan baik. jika tidak disertai port, maka kemunngkinan ada firewall yang menahan hak akses untuk membuat socket pada IP tersebut. semoga berhasil

bayu Said:  

dok, saya kurang ngerti masalah setting ip yg di file php, yg mana aj yg perlu diubah ip na? apa cuma yg ini aj define(“_IPROUTER”, “192.168.1.1″); ? mohon pencerahanna..

bayu Said:  

dok, saya kurang ngerti ma setting ip yg mau di cek di php, apa yg diganti cuma ini aj “define(“_IPROUTER”, “192.168.1.1″);” ?

tolong pencerahannya…

dr.emi Said:  

biasa nya IP router make itu, tapi sesuaikan saja kalo berbeda. kalo sama, ga perlu dirubah. yang pnting itu ip targetnya.
IP nya dicek, range nya dari berapa sampe barpa yang ada dalam jaringan, kalo make router biasanya 192.168.1.X, kalo ga make biasanya 192.168.0.x

bayu Said:  

trus klo ane mau cek ping antar komputer dalam jaringan bisa gk langsung pake ip komputer yg dituju?

kmarin ane coba ganti ip dsana pake ip komputer yg dituju tapi gk mau dia dok…

bayu Said:  

ane pake

define(“_IPROUTER”, “192.168.0.1″);
$address = “$ip”; //your public IP
$port = $p; // your IP open port

tapi bgitu dieksekusi gk nampil apa” dok, cuma kotak kosong doank… -_-

Hi.. ! Wanna say anything about my tutorial ?
Just say it with fill the comment form.
Comment Form
 

 
 
 
 
 
Category
stack