Get iPaddress of a computer in an Android project using java

I am using ksoap2-android , and I need to get the IP address using java, so I do not need to enter it manually every time.

What do I mean by IP address, for example, if I do ipconfig using the shell:
DNS suffix for connection:
Local IPv6 address. ,,: f0 :: ed2: e3bf: 8206: 44% 13
IPv4 address. ,,,,,: 192.168.1.107 <- THIS IS ONE
Subnet Mask. ,,,,,: 255.255.255.0
Default gateway. ,,,,: 192.168.1.1

The fact is that I am developing an application for Android, and the emulator has a different type of IP than the machine.
I need to get the IP address of the machine, how to do it?

Many thanks

+6
java android ip-address ip android-ksoap2
source share
4 answers
public String getLocalIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface .getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf .getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { Log.e(tag, ex.toString()); } return ""; } 
+8
source share

To get the iPaddress of your Android device, you use this code.

 WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); String ip = intToIp(ipAddress); public String intToIp(int i) { return ((i >> 24 ) & 0xFF ) + "." + ((i >> 16 ) & 0xFF) + "." + ((i >> 8 ) & 0xFF) + "." + ( i & 0xFF) ; } 
+4
source share

Try this link

http://www.droidnova.com/get-the-ip-address-of-your-device,304.html

also you can try this adb shell netcfg command

+2
source share
 InetAddress iA=InetAddress.getLocalHost(); System.out.println(iA.getHostAddress()); 

see also

+2
source share

All Articles