Simple security check for computer name

Various PHP Scripts
Post Reply
thockman
Site Admin
Posts: 104
Joined: Thu Dec 15, 2005 5:51 pm
Location: Kansas City
Contact:

Simple security check for computer name

Post by thockman » Thu Dec 15, 2005 11:03 pm

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;
}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest