bue... aca te pongo con un formulario para que puedas practicar y veas mas facilmente como es que funciona..
le agregue una validacion por si haces publica la pagina para que no te caguen el server...
Código PHP:
<?php
function FunVerificarTipo($dato){
$valores = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.';
$bolean = true;
$len_dato = strlen($dato);
for ($m=0;$m<$len_dato;$m++) {
if (strpos($valores,$dato{$m}) === false) {
$bolean = false;
break;
}
}
if ($bolean) {
return $dato;
}else{
return "";
}
}
function validaweb($web){
$web=htmlentities($_GET['web']);
$web=substr($web, 0, 30);
$reemplazar=array("http://","https://");
$por=array("","");
$web=str_replace($reemplazar,$por,$web);
$dominio=explode("/",$web);
$web=$dominio[0];
$web=FunVerificarTipo($web);
return $web;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>
<body>
<form id="form1" name="form1" method="get" action="">
<label>
IP / URL: <input name="web" type="text" value="<?php if(trim($_GET['web']) != ""){ echo htmlentities($_GET['web']); } ?>" size="50" maxlength="50" />
</label>
<label>
<input type="submit" name="Submit" value="Enviar" />
</label>
</form>
<strong>Dominio/IP:</strong>
<em>
<?php if (validaweb($web) != ""){ echo validaweb($web); }else{ echo "La url/ip que escribio no es valido..."; }?>
</em><br /><br /><hr /><br />
<div style="font-family:Courier New, Courier, monospace; color:#EEEEEE; background-color:#000000; font-size:14px;">
<div style="margin:15px;">
<?php
if (validaweb($web) != ""){
$web=validaweb($_GET['web']);
$comando = exec('ping '.$web, $retval);
foreach ($retval as $lineas){
echo htmlentities($lineas).'<br />';
}
}
?><blink>_</blink><br /><br /></div>
</div>
</body>
</html>