$ENV{'REMOTE_ADDR'} - ??? (Posted by fairhousing)

They have: 1,587 posts

Joined: Mar 1999

hello:

currently when i use $ENV{'REMOTE_ADDR'} to record an ip i get something like this 271.3.47.10 Is there any way to stop the number after the last period from being logged, if so how?

some sample code would be greatly appreciated

thanks in advance Wink

----------
My Site Got Hacked, Check It Out!
http://www.birminghamnet.com

Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?

They have: 69 posts

Joined: Apr 1999

Code:

$IP = $ENV{'REMOTE_ADDR'};
$IP =~ s/(.+?)\.(.+?)\.(.+?)\.(.+?)/$1.$2.$3/;

Haven't tested it but should work just fine Smiling

----------
Reviews of the best resources for webmasters in your e-mail every week!
Subscribe for [red]FREE[/red] by going to http://www.web-reviews.com/

He has: 150 posts

Joined: Apr 1999

Here's some simple code that should do what you want.

-------------------
#!/usr/bin/perl

$ip=$ENV{'REMOTE_ADDR'};
@numbers=split(/\./,$ip);

$newip="@numbers[0].@numbers[1].@numbers[2]";

print "Content-Type: text/plain\n\n";
print "Your real IP address: $ip\n";
print "Here's how it looks now: $newip\n";
-------------------

I'm sure there are better ways to do it, but this is the simplest way.

Hope this helps! Wink

They have: 69 posts

Joined: Apr 1999

My code was shorter Smiling

BTW... I just tested and it works.

----------
Reviews of the best resources for webmasters in your e-mail every week!
Subscribe for [red]FREE[/red] by going to http://www.web-reviews.com/

They have: 1,587 posts

Joined: Mar 1999

whow! wish all my post got this quick of a helpful response.

thanks to the both of u Wink

----------
My Site Got Hacked, Check It Out!
http://www.birminghamnet.com

Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.