Click to See Complete Forum and Search --> : how to find external IP add.


AceSpy
December 27th, 2003, 12:57 PM
Friends,

I am writting a program to find the external IP address of the client computer, I want to know what code the guy at showmyip.com uses to display the IP of the computer making the request which I am interested in using in my site+program.

Thanks,
AceSpy

thejag
December 27th, 2003, 02:49 PM
first glance at the webpage i thought itd be a javascript, but when i looked at page's source code, i couldn't find the line, so i went to the next place and found a javascript that would show the viewer's ip address:



<!-- ONE STEP TO INSTALL IP ADDRESS:

1. Copy the coding into the HEAD of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
// http://www.kdcgrohl.com

// Depending on your server set-up,
// you may need to use the ".shtml"
// extension [instead of the "html"
// or "htm"] as the script uses Server
// Side Includes. To display in the
// title bar, exclude the
//"<title></title>" code from the page.

// This part gets the IP
var ip = '<!--#echo var="REMOTE_ADDR"-->';

// This part is for an alert box
alert("Your IP address is "+ip);

// This part is for the status bar
window.defaultStatus = "Your IP address is "+ip;

// This part is for the title bar
document.write("<title>Your IP address is "+ip+"</title>");
// End -->
</script>


<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 1.09 KB -->


from: http://javascript.internet.com/user-details/ip-address.html

DeathIncarnate
December 29th, 2003, 09:57 PM
They did use javascript at showmyip.com, but there is an easier way but requires more.

PHP is an easy language for things like this because its a lot less code and does so much more, but it does require php installed on the server.

Example page:

<html>
<body>
<?php
echo "<p>Your ip is $REMOTE_HOST</p>"
?>
</body>
</html>

And the browser output would be:

Your ip is 127.0.0.1 (this would actually be your real ip)


Hope that helps, PHP is very useful


PHP links:

PHP Homepage (http://www.php.net)
A nice site to learn from (http://www.phpworld.com/articles/2000.02/intro_000.html)

- DeathIncarnate

pwaring
December 29th, 2003, 10:00 PM
That PHP code won't work on newer versions of PHP, because register_globals is off by default (and rightly so). You'd need to replace $REMOTE_HOST with $_SERVER['REMOTE_HOST'] in order for it to work.

AceSpy
December 30th, 2003, 03:04 AM
Is there any way to do it in CGI/Perl?

AceSpy
www.acespy.com

skiddieleet
December 30th, 2003, 06:06 AM
this should help http://www.raingod.com/raingod/resources/Programming/Perl/Notes/UserInfo.html
you should try searching google for "getting ip with cgi". That's how I got that page. Good luck.

brt4c
January 8th, 2004, 12:52 PM
#!/usr/bin/perl
use CGI qw(:standard);

print "Content-type:text/html\n\n";
print "Your IP address is: ".$ENV{REMOTE_ADDR};

#I love you Perl...