Jacopo Nuzzi
a- a+

Ricavare IP & Hostname

Con Php è possibile ricavare l'indirizzo IP da un Hostname e viceversa.
Le funzioni che ci permettono di fare ciò sono:

  • gethostbyaddr(), per ricavere l'Hostname
  • gethostbyname(), per ricavere l'IP

Ecco il codice:

<?PHP
    $from = $HTTP_GET_VARS["f"];
    $query = $HTTP_GET_VARS["q"];
        if ($query != "")
        {
            if ($from == "IP")
            {
                $host = gethostbyaddr($query);
                echo "L'hostname di <em>".$query."</em> è <strong>".$host."</strong>.";
            }
            else if ($from == "Host")
            {
                $ip = gethostbyname($query);
                echo "L'indirizzo IP di <em>".$query."</em> è <strong>".$ip."</strong>.";
            }
            else
            {
                exit("Errore!");
            }
        }
        else
        {
            exit("Errore!");
        }
?>

Ti potrebbe interessare anche

commenta la notizia

C'è 1 commento
Marcello
Ti è piaciuto l'articolo?