<?php
//==============================================================================================
// getIP: retrieve the IP address of a hostname 
//==============================================================================================

    error_reporting(0);

    if (isset($_GET))                                   //if not first time around
        getIP();                         

    display_data();                         

//==============================================================================================
function getIP()
{
    global $host, $ip, $output;

    $host    = $_GET['host'];
    $option  = $_GET['opt'];

    if (! $host)
        return;

    $ip = ($option == 'name') ? gethostbyname($host) : gethostbyaddr($host); 
    
    $x = exec("whois $host", $output); 
   
}

//=============================================================================
function display_data()
{
    global $host, $ip, $output;
?>
    <html>
    <body bgcolor=lightyellow>
    <br>
    <form action=<?php echo $_SERVER['PHP_SELF']?> >
    <label for=host><b> Enter a Host Name or IP Address </b></label>
    <input  id=host type=text  name=host value=<?php echo $host ?> > 
    <input  id=bttn type=submit          value='  get  '           > 
    <input  id=opt  type=radio name=opt  value='name' checked      > 
    Name
    <input  id=opt  type=radio name=opt  value='addr'              > 
    Address
    <hr>
    <br>

<?php
    echo "<div style='border:1px solid black; background-color:white; width:460px; height:40px'>";

    echo "<b> $ip </b><br>";

    foreach($output as $line)
        echo "$line <br>";

    echo "</div>";    
}
?>
    </body>
    </html>