Re: [PHP] determining client's external IP

2006-03-13 Thread Miles Thompson

At 02:39 PM 3/13/2006, tedd wrote:


Jochem wrote:


life is not that simple here are some functions I wrote as an attempt to
to better than 'REMOTE_ADDR' - interested if these allow you to retrieve the
same IP as whatismyip.com:


-snip-

A most impressive piece of code -- thank you, it works great!

While you appear to get down to the person's IP, where would one get the 
assorted associated details, such as the IP location text, Reverse IP (if 
any) and Reverse DNS?


For example, such as that provided by:

http://whois.sc

Do these people have access to dB's that civilians don't?

tedd
--

http://sperling.com



Tedd,

Try this link.
http://www.ip2location.com/articles/article2.htm

ip2location.com also have a free database of IP's.

Google turns up others, they are all roughly similar.

HTH - Miles


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.375 / Virus Database: 268.2.1/279 - Release Date: 3/10/2006

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] determining client's external IP

2006-03-13 Thread tedd

Jochem wrote:


life is not that simple here are some functions I wrote as an attempt to
to better than 'REMOTE_ADDR' - interested if these allow you to retrieve the
same IP as whatismyip.com:


-snip-

A most impressive piece of code -- thank you, it works great!

While you appear to get down to the person's IP, where would one get 
the assorted associated details, such as the IP location text, 
Reverse IP (if any) and Reverse DNS?


For example, such as that provided by:

http://whois.sc

Do these people have access to dB's that civilians don't?

tedd
--

http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [SPAM] [PHP] determining client's external IP

2006-03-13 Thread joseph
this is what gnuboard4 uses to process logins

$tmp_sql = " insert into $g4[login_table] ( lo_ip, mb_id, lo_datetime,
lo_location, lo_url ) values ( '$_SERVER[REMOTE_ADDR]',
'$member[mb_id]', '$g4[time_ymdhis]', '$lo_location',  '$lo_url' ) ";^M

i thought about proxy proxy servers upstream from user?  popular of SOHO
or office environments but not for home users?... but
BUT you say you are getting diff ip from watismyip.com so it can't be
the proxy.

anyway, gnuboard4 is well coded.  i can't believe SERVER[remote_addr] is
at fault.


2006-03-12 (일), 20:20 -0500, David Calkins 쓰시길:
> My web page needs to determine the client's external IP address, i.e., the
> IP address that others viewing the web page would be able to use to contact
> that user's machine (assuming they've setup the appropriate forwarding into
> their actual machine of course).  In this environment the clients want 
> their external
> IP to be correctly reported, so there's no issue of people trying to 
> spoof and
> show a wrong IP.
> 
> I'm currently using $_SERVER['REMOTE_ADDR'] as this seemed like the best
> approach as I thought it would yield the IP as seen from the web server and
> hence, hopefully, as seen by everyone else on the internet.
> 
> This works in many cases, but in a couple cases users have reported issues
> with others not being able to use the IPs the web page reports to 
> contact their
> machines.  In these cases the $_SERVER['REMOTE_ADDR'] seems to be returning
> a different IP than what www.whatismyip.com  
> returned, for example.
> 
> Is there another reccomended way to get the client's externally visible IP
> address?  Or is $_SERVER['REMOTE_ADDR'] the right approach but might
> not always work?
> 
> Thanks!
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [SPAM] [PHP] determining client's external IP

2006-03-13 Thread joseph
this is what gnuboard4 uses to process logins

$tmp_sql = " insert into $g4[login_table] ( lo_ip, mb_id, lo_datetime,
lo_location, lo_url ) values ( '$_SERVER[REMOTE_ADDR]',
'$member[mb_id]', '$g4[time_ymdhis]', '$lo_location',  '$lo_url' ) ";^M

i thought about proxy proxy servers upstream from user?  popular of SOHO
or office environments but not for home users?... but
BUT you say you are getting diff ip from watismyip.com so it can't be
the proxy.

anyway, gnuboard4 is well coded.  i can't believe SERVER[remote_addr] is
at fault.



2006-03-12 (일), 20:20 -0500, David Calkins 쓰시길:
> My web page needs to determine the client's external IP address, i.e., the
> IP address that others viewing the web page would be able to use to contact
> that user's machine (assuming they've setup the appropriate forwarding into
> their actual machine of course).  In this environment the clients want 
> their external
> IP to be correctly reported, so there's no issue of people trying to 
> spoof and
> show a wrong IP.
> 
> I'm currently using $_SERVER['REMOTE_ADDR'] as this seemed like the best
> approach as I thought it would yield the IP as seen from the web server and
> hence, hopefully, as seen by everyone else on the internet.
> 
> This works in many cases, but in a couple cases users have reported issues
> with others not being able to use the IPs the web page reports to 
> contact their
> machines.  In these cases the $_SERVER['REMOTE_ADDR'] seems to be returning
> a different IP than what www.whatismyip.com  
> returned, for example.
> 
> Is there another reccomended way to get the client's externally visible IP
> address?  Or is $_SERVER['REMOTE_ADDR'] the right approach but might
> not always work?
> 
> Thanks!
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] determining client's external IP

2006-03-13 Thread Satyam


- Original Message - 
From: "David Calkins" <[EMAIL PROTECTED]>

To: 
Sent: Monday, March 13, 2006 2:20 AM
Subject: [PHP] determining client's external IP



My web page needs to determine the client's external IP address, i.e., the
IP address that others viewing the web page would be able to use to 
contact
that user's machine (assuming they've setup the appropriate forwarding 
into
their actual machine of course).  In this environment the clients want 
their external
IP to be correctly reported, so there's no issue of people trying to spoof 
and

show a wrong IP.

I'm currently using $_SERVER['REMOTE_ADDR'] as this seemed like the best
approach as I thought it would yield the IP as seen from the web server 
and

hence, hopefully, as seen by everyone else on the internet.

This works in many cases, but in a couple cases users have reported issues
with others not being able to use the IPs the web page reports to contact 
their
machines.  In these cases the $_SERVER['REMOTE_ADDR'] seems to be 
returning
a different IP than what www.whatismyip.com <http://www.whatismyip.com> 
returned, for example.


Is there another reccomended way to get the client's externally visible IP
address?  Or is $_SERVER['REMOTE_ADDR'] the right approach but might
not always work?

Thanks!




Due to the shortage of IP addresses (there are only 32bits, with gaps of 
unused addresses in between and there are many more devices than ever 
thought possible), IP addresses are reused.  ISP translate the IP addresses 
clients use within their network to any of the pool of valid IP addresses 
they have licensed from ICANN.  This assignment is dynamic and quite 
unpredictable, it might change every single day, it might be stable for 
months and change suddenly.  It depends on the ISP, nothing you can do on 
your side, what you are getting now is as good as you'll ever get.


Both HTTP proxies and routers with NAT (Network Address Translation) do this 
automatically.  Outside addresses obtained from devices that reach the 
outside world through any of these devices are not reachable from the 
outside, you cannot connect to any service they might be offering, because 
the translation does not work backwards.


Satyam

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] determining client's external IP

2006-03-13 Thread Jochem Maas

David Calkins wrote:

My web page needs to determine the client's external IP address, i.e., the
IP address that others viewing the web page would be able to use to contact
that user's machine (assuming they've setup the appropriate forwarding into
their actual machine of course).  In this environment the clients want 
their external
IP to be correctly reported, so there's no issue of people trying to 
spoof and

show a wrong IP.

I'm currently using $_SERVER['REMOTE_ADDR'] as this seemed like the best
approach as I thought it would yield the IP as seen from the web server and
hence, hopefully, as seen by everyone else on the internet.

This works in many cases, but in a couple cases users have reported issues
with others not being able to use the IPs the web page reports to 
contact their

machines.  In these cases the $_SERVER['REMOTE_ADDR'] seems to be returning
a different IP than what www.whatismyip.com  
returned, for example.


Is there another reccomended way to get the client's externally visible IP
address?  Or is $_SERVER['REMOTE_ADDR'] the right approach but might
not always work?


life is not that simple here are some functions I wrote as an attempt to
to better than 'REMOTE_ADDR' - interested if these allow you to retrieve the
same IP as whatismyip.com:

/* Determine if an ip is in a net.
 * E.G. 120.120.120.120 in 120.120.0.0/16
 */
function isIPInSubnet($ip, $net, $mask)
{
$firstpart  = substr(str_pad(decbin(ip2long($net)), 32, "0", STR_PAD_LEFT) 
,0 , $mask);
$firstip= substr(str_pad(decbin(ip2long($ip)), 32, "0", STR_PAD_LEFT), 
0, $mask);

return (strcmp($firstpart, $firstip) == 0);
}

/* This function check if a ip is in an array of nets (ip and mask) */
function isPrivateIP($theip)
{
foreach (array("10.0.0.0/8",
   "172.16.0.0/12",
   "192.168.0.0/16") as $subnet)
{
list($net, $mask) = explode('/', $subnet);
if(isIPInSubnet($theip,$net,$mask)) {
return true;
}
}

return false;
}

/* Building the ip array with the HTTP_X_FORWARDED_FOR and REMOTE_ADDR HTTP 
vars.
 * With this function we get an array where first are the ip's listed in
 * HTTP_X_FORWARDED_FOR and the last ip is the REMOTE_ADDR
 */
function getRequestIPs()
{
$ipList = array();

foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_FORWARDED_FOR', 'REMOTE_ADDR') 
as $key) {
if (isset($_SERVER[$key]) && $_SERVER[$key]) {
$ipList = array_merge($ipList, explode(',', $_SERVER[$key]));
break;
}
}

return $ipList;
}

/* try hard to determine whAt the users/clients public IP address is */
function getRequestIP($allowPrivIPs = false)
{
foreach (getRequestIPs() as $ip) {
if($ip && ($allowPrivIPs === true || !isPrivateIP($ip))) {
return $ip;
}
}


return 'unknown';
}




Thanks!



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] determining client's external IP

2006-03-12 Thread David Calkins

My web page needs to determine the client's external IP address, i.e., the
IP address that others viewing the web page would be able to use to contact
that user's machine (assuming they've setup the appropriate forwarding into
their actual machine of course).  In this environment the clients want 
their external
IP to be correctly reported, so there's no issue of people trying to 
spoof and

show a wrong IP.

I'm currently using $_SERVER['REMOTE_ADDR'] as this seemed like the best
approach as I thought it would yield the IP as seen from the web server and
hence, hopefully, as seen by everyone else on the internet.

This works in many cases, but in a couple cases users have reported issues
with others not being able to use the IPs the web page reports to 
contact their

machines.  In these cases the $_SERVER['REMOTE_ADDR'] seems to be returning
a different IP than what www.whatismyip.com  
returned, for example.


Is there another reccomended way to get the client's externally visible IP
address?  Or is $_SERVER['REMOTE_ADDR'] the right approach but might
not always work?

Thanks!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php