Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Trying to determine IP provided by ISP

Hi Friends,

Does anybody have a PHP script which can return the external IP provided by the ISP?  The purpose is rather convoluted, however I'am trying to manage these dynamically allocated IP's.

My Web server is located behind a router or a proxy.

How do I get this IP when called within the Local network?

Thanks
Arnnie
0
Arnnie
Asked:
Arnnie
1 Solution
 
AhmadKhatibCommented:
<?
//Get users IP Address
$ipaddress = ($HTTP_SERVER_VARS["REMOTE_ADDR"]);
?>
0
 
carchitectCommented:
yeah he is right....

$ip=getenv("REMOTE_ADDR");

regards


0
 
Big_Red_DogCommented:
I would recommend the new way since the old way will be deprecated...

$ipaddr=$_SERVER['REMOTE_ADDR'];
0
 
birdgenjCommented:
In order to obtain the IP address from behind a firewall you need to run a PHP script on a webserver outside the router.

So, for example:

place a php file on a cheap webserver (or a friend's) that checks the IP address of the visitor -- using the methods listed above, then have it return the IP address from a function on that page.

Here is some sample source code:

setip.php
<?php

// Pass the hash and the auth to ensure nobody else can access this. change to whatever you want.
if ($hash == "security" && $auth="function"){
     $newip = $REMOTE_ADDR;
     $fp = fopen ("currentip.txt", "wb+");
     fputs($fp, $REMOTE_ADDR);
     fclose ($fp);
     echo 'status='.$REMOTE_ADDR;
} else {
echo 'status=FAILED. ACCESS DENIED';
}

status.php
<?php

$fp = fopen("currentip.txt", "r");
$contents = fread ($fp, filesize ("currentip.txt"));
fclose($fp);

$fp = @fopen("http://".$contents."/index.php","r");
if ($fp)
{ print"sitestatus=online"; }
else
{ print"sitestatus=offline"; }

?>

Now all you need to do is make a file that loads the data from the currentip.txt, and redirects to: http://".$contents."/index.php

Hopefully that helps out your problem.
0
 
ArnnieAuthor Commented:
Thanks for the advice.

The solution you've mentioned is what I suspected.  I just wanted to avoid third party webservers for redundancy purposes.

Thanks again.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now