<HTML>
<HEAD>
<TITLE>怎么利用PHP去ping一个地址</TITLE>
<!--
/***************************
* 孟宪会
* [email protected]
* http://elove.heha.net
* http://go.163.com/~colorweb
***************************
//-->
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<FORM method='POST' action='<?php echo $PHP_SELF;?>'>
<table border=1 cellspacing=0 cellpadding=1 width="400" bgcolor=#808080>
<tr>
<th colspan=2 align=center>怎么利用PHP去ping一个地址</th>
</tr>
<tr>
<th bgcolor=#066b98>请输入url或ip地址:</th>
<td><INPUT type='text' name='server' size='30' maxlength='30'></td>
</tr>
<tr>
<td>?lt;/td>
<td><INPUT type='submit' value='发送' Onclick="this.value='Pinging...'"></td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
<?php
if(($server == '127.0.0.1') | | ($server == 'localhost') | | ($server == getenv("SERVER_ADDR"))) {
echo "<HR noshade size=1<br>";
echo "<font color=red size=1>Fuck Off!</font><br>";
echo "<HR noshade size=1<br>";
exit;
} else {
if($server =="") {
echo "<H2>请输入url或ip地址:</H2>";
exit;
}
$ip = getenv("REMOTE_ADDR");
$hname = getenv("HTTP_HOST");
echo "<b>Your IP is:</b> <i>$ip</i><br>"
."<b>Trying to ping:</b> <i>$server</i><br>"
."<b>Using server:</b> <i>$hname</i>";
echo "<HR noshade size=1<br>";
echo "<b>STATS:</b><br><br>";
$command = "ping -c4 $server";
exec($command, $result, $rval);
if(count($result) <= 0) {
echo "<font color=red>没有响应</font><br>";
echo "<HR noshade size=1>";
exit;
}
for ($i = 0; $i < count($result); $i++) {
echo "<font color=red>$result[$i]</font><br>";
}
echo "<HR noshade size=1>";
#include("powered.txt");
}
?>
本文地址:http://com.8s8s.com/it/it30507.htm