Page 1 of 1

Simple security check for computer name

Posted: Thu Dec 15, 2005 11:03 pm
by thockman
This script will us reverse lookup to determine the users computername.
The function gethost() get the name using the remote_addr veriable.
Then the case checks for approved computers. I found the function surfing then just added what I needed.

Code: Select all

// Simple security using IP address.
$rmtip = $_SERVER['REMOTE_ADDR'];
$hostname = substr(gethost($rmtip), strpos(gethost($rmtip), "."));
switch ($hostname):
        case computername:
                $auth = "ok";
                break;
        default:
                echo "Sorry, you do not have access to this page.<br>
                     If you believe you should have access please contact so in so</b></center>";
                exit();
endswitch;
// End of IP check.

// Function to get computer name.
function gethost($ip)
{
   $host = `host $ip`;
   $host = end(explode(' ',$host));
   $host = substr($host,0,strlen($host)-41);
   $chk = split("\(",$host);
   if($chk[1]) return $ip." (".$chk[1].")";
   else return $host;
}