Hi..
Is there possible way to get the IP address that assigned
to the mobile while it connected to some host?
Voravit H.
phoumlib
2004-04-09, 14:48
Hi
if you have your own web server, you can return the remote host variable to the midlet.
Or simply make a connection from the midlet to some web sites that return the ip address such as http://www.whatismyip.com/
phoumlib's suggestion may not actually tell you what you want to know.
On a typical carrier network, the phone is behind a NAT firewall. The phone itself has a non-routable IP address (usually 10.somthing). When it connects to something outside, the NAT firewall rewrites the address headers so that the connection seems to have come from the NAT itself. Thus whatismyip.com will report the external IP address of the carrier network's NAT box rather than that of the phone.
If for some reason you want the IP address of the phone, you can only get this in MIDP-2 -- MIDP-1 doesn't have the capability. In MIDP-2, establish a connection to any external host, then use the Connection.getLocalAddress() method on this connection. This may only work if you have actually sent some data on this connection, though: If the GPRS connection is idle, getLocalAddress() may just report 127.0.0.1.
Note that the IP address of the phone is NOT something that you can connect to from outside -- it's generally a non-routable address -- and is NOT guaranteed to be stay the same if the phone roams between cells. Unless you're using a protocol like STUN, you are probably going in a wrong direction looking at the phone's address.
--G
Thank you for your kindness :D