Forum Moderators: bakedjake

Message Too Old, No Replies

simple IP redirect

         

noob999

6:51 pm on Apr 1, 2004 (gmt 0)

10+ Year Member



- I need a really simple way to redirect one person's IP to a specific page.

- I know that his hostname will always be name.corp.whatever.com. Not sure if this will always redirect to the same IP.

- I only need to do the redirect for this one IP.

- I do not have access to Apache server configuration or .htaccess files. Would like a way to just do this in Perl CGI if possible.

Thanks,

noob999

martin

7:30 pm on Apr 1, 2004 (gmt 0)

10+ Year Member



print "Location: http:// google.com\n\n";

noob999

11:23 pm on Apr 1, 2004 (gmt 0)

10+ Year Member



thanks, but that doesn't explain the IP detection part of the question

VectorJ

2:44 am on Apr 3, 2004 (gmt 0)

10+ Year Member



If you only have access to the IP, you can use the Socket module to get the IP, translate it to a hostname, then redirect as you see fit:

use Socket;
$ipaddr = inet_aton($ENV{'REMOTE_ADDR'});
$host = gethostbyaddr($ipaddr, AF_INET);
if ($host = 'badguy.whatever.com') {
print "Location: http://example.com\n\n";
}

If all you need is the IP, $ENV{'REMOTE_ADDR'} will give it to you.

Otherwise you can just pull the hostname directly from $ENV{'REMOTE_HOST'}