INTERNET EXPLORER? Ti consiglio di navigare questo sito con Mozilla Firefox oppure con Google Chrome.

Ricavere IP e Hostname con Php

Siti dinamici con PHP
Impara a creare siti dinamici professionali con PHP

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!");
        }
?>

IN EVIDENZA

HOT LINKS