Outils pour utilisateurs

Outils du site


php:netutil

URL network utils

Petite collection utile pour avoir des infos diverses:

  • en-têtes serveur
  • informations du certificat SSL
  • résolutions DNS
  • whois, ping, traceroute…

Ça passe par exec() pour utiliser curl, openssl, nslookup, dig, ping, traceroute et whois. Faut juste s'assurer que le système sur lequel tourne le script dispose bien de ces outils.

NB: il n'y a aucune sécurité basique (échappement et contrôle d'entrée, antiflood..) donc à ne pas laisser en accès public.

netutil.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>URL network utils</title>
<style type="text/css">
body {font-family:monospace;}
pre {border:1px solid #aaa;padding:1em;}
pre#curl {display:none;background:linear-gradient(to bottom, lightgrey, white);}
pre#ssl {display:none;background:linear-gradient(to bottom, lightyellow, white);}
pre#host {display:none;background:linear-gradient(to bottom, lightgreen, white);}
pre#dig {display:none;background:linear-gradient(to bottom, orangered, white);}
pre#ping {display:none;background:linear-gradient(to bottom, lightblue, white);}
pre#traceroute {display:none;background:linear-gradient(to bottom, wheat, white);}
pre#whois {display:none;background:linear-gradient(to bottom, mediumspringgreen, white);}
pre#nslookup {display:none;background:linear-gradient(to bottom, sandybrown, white);}
</style>
</head>
<body>
<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>
 
<?php
 
if(!isset($_GET['url']))
{
?>
 
<form action="./netutil.php"  method="get">
 <input type="text" name="url" placeholder="URL...">
 <input type="submit">
</form>
 
<?php
}
else {
$request = $_GET['url'];
 
echo '<form action="./netutil.php"  method="get">
 <input type="text" name="url" placeholder="'.$request.'">
 <input type="submit">
</form><br><a href="#curl" onclick="toggle_visibility(\'curl\');">headers</a> | <a href="#ssl" onclick="toggle_visibility(\'ssl\');">SSL cert</a> | <a href="#host" onclick="toggle_visibility(\'host\');">host</a> | <a href="#dig" onclick="toggle_visibility(\'dig\');">dig</a> | <a href="#ping" onclick="toggle_visibility(\'ping\');">ping</a> | <a href="#traceroute" onclick="toggle_visibility(\'traceroute\');">traceroute</a> | <a href="#whois" onclick="toggle_visibility(\'whois\');">whois</a> | <a href="#nslookup" onclick="toggle_visibility(\'nslookup\');">nslookup</a>';
 
if(strpos($request, '/') !== FALSE)
  $host = parse_url($request, PHP_URL_HOST);
else 
  $host = $request;
 
echo "<pre id=\"curl\"><b>curl -I (HTTP headers)</b> [ $request ]<hr><br><br>";
exec('curl -I '.$request, $out);
foreach ($out as $data)
 echo "$data<br>";
unset($out);
echo '<br><a href="#" onclick="toggle_visibility(\'curl\');">close</a></pre>';
 
echo "<pre id=\"ssl\"><b>openssl s_client/x509 (SSL certificate check)</b> [ $host ]<hr><br><br>";
exec('openssl s_client -servername '.$host.' -connect '.$host.':443 | openssl x509 -noout -text', $out);
foreach ($out as $data)
 echo "$data<br>";
unset($out);
echo '<br><a href="#" onclick="toggle_visibility(\'ssl\');">close</a></pre>';
 
echo "<pre id=\"host\"><b>host (DNS summary)</b> [ $host ]<hr><br><br>";
// simple host mode
exec('host '.$host, $out);
foreach ($out as $data)
 echo "$data<br>";
unset($out);
echo '<br><a href="#" onclick="toggle_visibility(\'host\');">close</a></pre>';
 
echo "<pre id=\"dig\"><b>dig (DNS digging)</b> [ $host ]<hr><br><br>";
// dig
exec('dig '.$host, $out);
foreach ($out as $data)
 echo "$data<br>";
unset($out);
echo '<br><a href="#" onclick="toggle_visibility(\'dig\');">close</a></pre>';
 
 
echo "<pre id=\"ping\"><b>ping (host latency)</b> [ $host ]<hr><br><br>";
// ping
exec('ping -c5 -i 0.3 '.$host, $out);
foreach ($out as $data)
 echo "$data<br>";
unset($out);
echo '<br><a href="#" onclick="toggle_visibility(\'ping\');">close</a></pre>';
 
 
echo "<pre id=\"traceroute\"><b>traceroute (packet path overview)</b> [ $host ]<hr><br><br>";
//traceroute
exec('traceroute -q1 -w1 '.$host, $out);
foreach ($out as $data)
 echo "$data<br>";
unset($out);
echo '<br><a href="#" onclick="toggle_visibility(\'traceroute\');">close</a></pre>';
 
 
echo "<pre id=\"whois\"><b>whois (domain name information)</b> [ $host ]<hr><br><br>";
//whois
exec('whois '.$host, $out);
foreach ($out as $data)
 echo "$data<br>";
unset($out);
echo '<br><a href="#" onclick="toggle_visibility(\'whois\');">close</a></pre>';
 
echo "<pre id=\"nslookup\"><b>nslookup (DNS records)</b> [ $host ]<hr><br><br>";
//nslookup
exec('nslookup -query=any '.$host, $out);
foreach ($out as $data)
 echo "$data<br>";
unset($out);
echo '<br><a href="#" onclick="toggle_visibility(\'nslookup\');">close</a></pre>';
 
} ?>
</body>
</html>
php/netutil.txt · Dernière modification: 2013/08/20 12:07 par mitsu