Digital Survivors
 

Displaying Partial IP Addresses Using PHP

Scott Manning
August 25, 2003 | Comments (12)

For those of you who run community-type websites where people can post comments directly to your pages, you know the woes of dealing with people who post under fake names. Although I'm all for freedom of speech and privacy, when the same guy posts 15 times under names like "Bob Joe", "Jan", "ODB", and "Bill Clinton", it gets a little annoying. It is especially annoying when the same person is trying to create the illusion that there are 15 different people with the same opinion as them.

To deal with this, I'm now displaying partial IP Addresses next to comments on any site I work on. An IP Address of 666.66.78.234 will now be displayed next to a username as xxx.66.78.234 (Example). It still gives a little privacy, but allows readers to realize that Bob Joe, Jan, ODB, and Bill Clinton are all the same person.

How to display the partial IP Addresses
If you can at least get the IP address, you can display part of it using PHP. The code looks like so:

<?php
$ip = "999.99.99.999";
$quads = split('\.', $ip);
$quads[0] = ereg_replace("[0-9]", "x", $quads[0]);
$concealed = join(".", $quads);
print $concealed;
?>

"999.99.99.999" would of course be the IP Address you want to display partially. This code takes all numbers before the first period (.) in an IP Address and replaces them with x's. The final result in the above example would be xxx.99.99.999

Using this code with Movable Type
If you already have comments set up on Movable Type, you can add the following code to implement the same feature:

<?php
$ip = "<$MTCommentIP$>";
$quads = split('\.', $ip);
$quads[0] = ereg_replace("[0-9]", "X", $quads[0]);
$concealed = join(".", $quads);
print $concealed;
?>

The above code would need to be in between the <MTComments> tags.

Using this code with Greymatter
You can use the following code to implement the same feature in Greymatter:

<?php
$ip = "{{commentauthorip}}";
$quads = split('\.', $ip);
$quads[0] = ereg_replace("[0-9]", "X", $quads[0]);
$concealed = join(".", $quads);
print $concealed;
?>

Using this code on non-PHP pages
If you at least have PHP installed on your server, you can use this code on web pages even if they don't have the .php extension.

First, create a file in your root web directory called ".htaccess" (without the quotation marks). The root web directory is where your index file would reside.

In the file, put the following code:
AddType application/x-httpd-php .html .htm

The above code makes it so files with a .html or .htm extension will be treated like PHP files. To add more extension types, just add them at the end of the code. Be sure to put a space between each type.

That's it.

Hopefully, if more and more people start using this code, we can put a choke on the anonymous people who post under fake names. We may also reveal all those people who seem honest, but have 15 different sock puppets in their arsenal.

If you use this code, post a link to your site here. I'd love to see it in action.


Enjoy this article? There's more. Digital Survivors is a source of articles, tutorials, reviews, and commentary on all things digital.

Stay informed with rss, our feed is permanently ad-free.

These articles are new:

bullet The Best Solution for the Financial Crisis
bullet Photos from the McCain/Palin Rally in Media, PA (9/22/08)
bullet Churchill's Earliest Warning About Hitler
bullet "Friendship with Germany" by Churchill (Sep 17, 1937)

If you don't immediately see what you want, you can start a topic in our forums.

 



Comments (12):
1) Posted by: Vera
August 26, 2003 2:12 AM

I wonder how you got the idea for this hack. ;-)


2) Posted by: Jim
September 2, 2003 5:50 PM

Of course, this is only a minor deterrent to those truly annoying posters who know how to circumvent this... in addition to the fact that the vast majority of ISPs dole out dynamic IPs. Otherwise, it's a great idea! :/


3) Posted by: Christian
September 3, 2003 4:11 AM

Um... there is no such thing as 666.xxx.xxx.xxx . You should brush up on your TCP/IP Networking. You are exposing privite information by doing this. Good idea but at least hide the first two octates.

Dude, what happened to the Matrix postings? We are now 2 months away!! I can't wait!


4) Posted by: Christian
September 3, 2003 4:17 AM

Also, Scott -- tweak it so there is always 3 xxx's.


5) Posted by: Scott Manning
September 3, 2003 6:56 AM

Christian,

The "666" is just an example; it's not real. The code is written so there will be two or three x's depending on whether or not there are two or three numbers before the first period.

RE: Matrix
The Matrix posts still exist. I'm just waiting for the new movie to inspire me to write some more stuff on it.

Scott


6) Posted by: Dan
November 1, 2003 3:05 AM

I run a message board with php and mysql. The board displays the users: name, e-mail(optional on my site), subject, and comments. It also displays the date and time of each the post. I would like to display the full IP and proxy of the users who post. Any suggestions?


7) Posted by: J
December 25, 2003 11:02 PM

I would like to display the full IP Address of Clients who post messages to webboard (my network use proxy server ). Please suggest.


8) Posted by: john
May 18, 2004 4:30 PM

hey, i managed to find out your website IP
it should be 69.5.28.75
am i rite


9) Posted by: Humberto
November 8, 2004 1:56 PM

You start displaying IP addresses on a site running pHp or any other community message board and watch your members drop like flies.
Ridiculous. The IP is the last edge of privacy for the individual. Who cares if someone posts under multiple names, the operator only needs to look at the log files and notify the rest of the usres (if appropriate).


10) Posted by: Aji
December 8, 2004 8:26 PM

I want to find the ip of any website (using input box) how can I do that, in dos I can say ping http://www.idealwebtools.com how can I do that using php.

Thanks
Aji


11) Posted by: Chris
March 29, 2005 11:01 PM

An easy way to display the IP Address on your web page on any web page....No Special Server Needed

Using javascript.
Go to this site
http://www.sendmyip.com/ipjava.htm
See it has the IP Address in the title and page.

Now view source on explorer and copy and paste all the HTML code it into your own html file.
And modify away................


12) Posted by: Raio
February 17, 2006 3:56 PM

Not always because there is many methods to hide ip
even if Java/Javascript enabled

1-method

Install Firewall on your machine and restrict all the connections to the Internet (except for the anonymous proxy server) from a browser. It's also recommended to use port mapping for this free anonymous proxy server and define the browser's proxy as 127.0.0.1 with the local port from port mapping.

2-method

Use socksification in your browser. This will enable relaying all the information your browser or any other software sends and transfers to the proxy server.

3�- THE Best Method

You need to set up LAN, local IP addresses (192.168.1.x or alike). A corporate proxy server should forwards ALL requests to a free anonymous proxy server (you need to have skills and rights of a system administrator in order to do that). It's impossible to connect to the Internet bypassing a corporate proxy, as long as external IP address is not assigned to local machines. It's also impossible to scan local machine's settings: even if Java/ActiveX applets detects and gives out your local IP address (192.168.1.x) to the web server, your anonymity will remain unbroken. So, basically, you can rate this option as 100% anonymity.

And "crackers" use chained of remotes cumputers for cracking , so very good system to stay anonymous.


border