yanqiufang 发表于 2017-4-1 08:39:47

怎么利用PHP去ping一个地址

  <HTML>
<HEAD>
<TITLE>怎么利用PHP去ping一个地址</TITLE>
<!--
/***************************
* 孟宪会
* amxh@21cn.com
* 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='发送' ></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");
}
?>
页: [1]
查看完整版本: 怎么利用PHP去ping一个地址