如何通过PHP PING IP
- 格式:doc
- 大小:13.50 KB
- 文档页数:2
<HTML>
<HEAD>
<TITLE>怎么利用PHP去ping一个地址</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<FORM method='POST' action="<?php echo $PHP_SELF;?>"> //返回本页面
<table border=1 cellspacing=0 cellpadding=1 width="400" bgcolor=#808080 align="center">
<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> </td>
<td><INPUT type='submit' value='发送' ></td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
<?php
$server=$_POST['server']; //接收查询的IP
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 ==null) //判断$server是否为空
{
echo "<H2>请输入url或ip地址:</H2>";
exit;
}
$ip = getenv("REMOTE_ADDR"); //调取本机IP
$hname = getenv("HTTP_HOST"); //调取服务器名称
echo "<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 -c 1 $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");
}
?>。