How to obtain a user's IP address
For some of our API queries the user's IP address is necessary. Below we have provided examples of how to obtain this IP address in a few languages.
Python
The following will return the client's IP address when run as a CGI script:
import os
ip_addr = os.environ["REMOTE_ADDR"]
Perl
The following will return the client's IP address when run as a CGI script:
PHP
In almost all cases the following PHP code will return the client's IP address:
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
$ip=$_SERVER['REMOTE_ADDR'];
}
Ruby
Use the following the get the client's IP address:
However, some say that the following is a better approach as it handles proxy-servers better:
ASP.NET
Use the following the get the client's IP address:
Java
Use the following the get the client's IP address:
However, some say that the following is a better approach as it handles proxy-servers better:
if(id_addr == null)
ip_addr = request.remote_ip
}
iPhone C Code
Unfortuately the iPhone SDK provides no simple way to get the device's current IP address. However, there do seem to be some workable solutions out there. The following resources may help:
http://blog.zachwaugh.com/post/309927273/programmatically-retrieving-ip-address-of-iphone
http://iphonesdksnippets.com/post/2009/09/07/Get-IP-address-of-iPhone.aspx
How Our API Works
Python
PHP
Ruby
Perl
ASP.NET
Java
Applescript
iPhone C