|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm making a web portal that has restricted amount of users.
Now, I need to increase the security on this site, and I've decided to use IP and hostmask for that. My problem is that I don't know how to get a user's IP or hostmask with Perl. Could someone tell me how to get it? - Kimppa
__________________
Fatal error on row 561: Couldn't access life - life isn't set |
|
#2
|
||||
|
||||
|
The absolute easiest way is to use CGI.pm to retrieve this information from the environment variables. In fact, CGI.pm makes pretty much all CGI programming easier.
Code:
use CGI; my $q= CGI->new(); my $ip_or_hostname=$q->remote_host(); This will put either the hostname of the client, or the IP if the hostname isn't available, into the $ip_or_hostname variable. Please don't think that IP or hostname based security is the be-all end-all though, this stuff can be spoofed. Building off your sig, the CGI.pm docs are at the address below: http://stein.cshl.org/WWW/software/CGI/ Good luck! |
|
#3
|
|||
|
|||
|
Ok, thanks, got the IP-thingie working.... but how about the hostmask?
I know that it isn't top-security to use only ip & hostmask control, but this thing I'm making doesn't need to be top-top-secure. |
|
#4
|
|||
|
|||
|
"Hostmask"
By "host mask", I assume you mean "network mask". You can't determine a client computer's netmask from another computer, and it would play no role in authentication.
If you're trying to limit access to a range of IP addresses, that's another question. If you're running Apache and want to restrict the site to machines in 192.168.1.???, put this in the .htaccess file in the directory you want to restrict: Order allow,deny Allow from 192.168.1.0/24 Read more about Apache's access control mechanisms at: URL |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > IP and hostmask |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|