How to find the IP Address of HTC Incredible on a CDMA Network
How can I find the IP address of the an HTC incredible connected to Verizon's network? My other question - do I have to make any changes to my App to ru开发者_开发问答n it on a cellular network? Till now the App was running on a Nexus One connected to a local Wi-Fi network.
Thanks.
Through mobile network, to check your IP run the command below:
ifconfig rmnet0
or application like 'Android Status' can be handy. Get it from the market.
To get IP address info look at this example. Might need a tweak for your CDMA.
You need not modify anything to get it working on Mobile n/w
You can use NetworkInterface.getNetworkInterfaces();, then addresses = intf.getInetAddresses(); to enumerate all the IP addresses on all the interfaces. You're looking for an address associated with a PDP.
That should work. I'm currently looking for a neater way.
To get the internal IP Address you can use the following snippet of code:
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = networkInterfaces.nextElement();
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress inetAddress = inetAddresses.nextElement();
byte[] address = inetAddress.getAddress();
}
}
Note: This will return the private network IP Address. If you want the public IP Address you will need to use STUN (try jSTUN).
Hope that helps!
精彩评论