View previous topic :: View next topic |
Author |
Message |
hc2995 -
Joined: 07 Aug 2006 Posts: 644 Location: Maryland, USA
|
Posted: Sun Nov 12, 2006 7:11 am Post subject: Displaying IP addresses with JavaScript? |
|
|
I wanted to kn ow hw do i display someones IP address using some sort of JS code? I have used JS before but i havent really gotten into the coding beyond basic (i dont use it very offten :/) _________________ Where have i been? School got heck-tick, had to move half way around the state, then back... and then i had to change jobs, so iv been away for a while :P |
|
Back to top |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sun Nov 12, 2006 10:54 am Post subject: |
|
|
You can't, but you can use SSI or any other CGI related scripting language to
put the IP Address into JavaScript. My examples use PHP and SSI.
Example: "test_java.php" (PHP)
Code: | <script language="JavaScript" type="text/javascript">
ipaddr = "<?php echo($_SERVER['REMOTE_ADDR']); ?>";
document.write("<b>Your IP:</b> ", ipaddr);
</script> |
Example: "test_java.shtm" (SSI)
Code: | <script language="JavaScript" type="text/javascript">
ipaddr = "<!-- #echo var="REMOTE_ADDR" -->";
document.write("<b>Your IP:</b> ", ipaddr);
</script> |
|
|
Back to top |
|
|
Treefog -
Joined: 01 Dec 2004 Posts: 2 Location: Canada (Lion's Head, Ontario)
|
Posted: Sun Nov 12, 2006 8:01 pm Post subject: Resolving Host name with PHP |
|
|
For anyone that’s interested:
This PHP script will display the users IP address and Host name.
Code: | <?php
/**
Display IP address and Host name via reverse DNS lookup
Notes:
1 - Your ISP's DNS servers MUST have reverse DNS lookup properly set up.
2 - The ISP for the IP address that you are resolving MUST have reverse DNS set up on their end.
3 - Page load time will be slowed down by the time taken to do the reverse DNS lookup.
In my case 2 to 4 seconds.
*/
$ip = $_SERVER['REMOTE_ADDR'];
$longisp = @gethostbyaddr($ip);
$isp = explode('.', $longisp);
$isp = array_reverse($isp);
$tmp = $isp[1];
if (preg_match("/\<(org?|com?|net)\>/i", $tmp)) {
$myisp = $isp[2].'.'.$isp[1].'.'.$isp[0];
} else {
$myisp = $isp[1].'.'.$isp[0];
}
if (preg_match("/[0-9]{1,3}\.[0-9]{1,3}/", $myisp))
$myisp = ' ';
// Display the results
echo "<div align='center' style='font-weight:bold'>";
echo"<p>";
if ($myisp == ' ')
// Reverse DNS lookup NOT valid, just show IP address
{echo "Your IP Address Is $ip";}
else
// Valid reverse DNS lookup, show IP address and HOST name
{echo "Your IP Address Is $ip ($myisp)";}
echo "<br>If you are behind a proxy, the IP address displayed above may not be yours.";
echo "</p>";
echo "</div>";
?> |
|
|
Back to top |
|
|
hc2995 -
Joined: 07 Aug 2006 Posts: 644 Location: Maryland, USA
|
Posted: Sun Nov 12, 2006 8:14 pm Post subject: |
|
|
k thnx :D _________________ Where have i been? School got heck-tick, had to move half way around the state, then back... and then i had to change jobs, so iv been away for a while :P |
|
Back to top |
|
|
|