웹에서 ping 체크를 해야할 경우 사용한다.
<?php
// This script was writen by webmaster@theworldsend.net, Aug.2001 // http://www.theworldsend.net // This is my first script. Enjoy. // // Put it into whatever directory and call it. That's all. // Updated to 4.2 code // Get Variable from form via register globals on/off //------------------------- $max_count = 10; //maximum count for ping command $unix = 1; //set this to 1 if you are on a *unix system $windows = 0; //set this to 1 if you are on a windows system // ------------------------- // nothing more to be done. // ------------------------- //globals on or off ? $register_globals = (bool) ini_get('register_gobals'); $system = ini_get('system'); $unix = (bool) $unix; $win = (bool) $windows; // If ($register_globals) { $ip = getenv(REMOTE_ADDR); $self = $PHP_SELF; } else { $submit = $_GET['submit']; $count = $_GET['count']; $host = $_GET['host']; $ip = $_SERVER['REMOTE_ADDR']; $self = $_SERVER['PHP_SELF']; }; // form submitted ? echo ' <style> body { background-color: #00aa99; color: #FFFFFF; } </style> '; If ($submit == "Ping!") { // over count ? If ($count > $max_count) { echo 'Maximum for count is: '.$max_count; echo '<a href="'.$self.'">Back</a>'; } else { // replace bad chars $host= preg_replace ("/[^A-Za-z0-9.-]/","",$host); $count= preg_replace ("/[^0-9.]/","",$count); echo '<body bgcolor="#FFFFFF" text="#000000"></body>'; echo("Ping Output:<br>"); echo '<pre>'; //check target IP or domain if ($unix) { system ("ping -c$count -w$count $host"); system("killall ping");// kill all ping processes in case there are some stalled ones or use echo 'ping' to execute ping without shell } else { system("ping -n $count $host"); } echo '</pre>'; } } else { echo '<body bgcolor="#FFFFFF" text="#000000"></body>'; echo '<p><font size="2">Your IP is: '.$ip.'</font></p>'; echo '<form methode="post" action="'.$self.'">'; echo ' Enter IP or Host <input type="text" name="host" value="'.$ip.'"></input>'; echo ' Enter Count <input type="text" name="count" size="2" value="4"></input>'; echo ' <input type="submit" name="submit" value="Ping!"></input>'; echo '</form>'; echo '<br><b>'.$system.'</b>'; echo '</body></html>'; } ?>
''.' Programs > PHP' 카테고리의 다른 글
윈도우 APACHE + PHP 연동시 오류 해결법. (1) | 2012.10.05 |
---|---|
PHP 에서 Magic Packet (WOL : 컴퓨터 원격 부팅) 을 보내는 소스. (0) | 2012.09.25 |
[PHP] 날짜 분, 초 차이 구하기. (0) | 2012.09.03 |
다차원 배열의 모든 값을 지정함수로 필터처리 (0) | 2012.07.05 |
[PHP] 리다이렉션 (페이지이동) 3가지 방법 (1) | 2012.07.04 |