I'm developing a mobile application in android.
Here I want to detect the IP address of the computer,system,etc after the usb tethering of the any android phone
I cannot find the solution.
If I put the following code then it takes the only the IP address of phone ,I need IP address of system
The following are code
ArrayList<InetAddress> arrayList=new ArrayList<InetAddress>();
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();
arrayList.add(inetAddress);
inetAddress=null;
}
}
} catch (SocketException ex) {
Log.e("SALMAN", ex.toString());
}
return arrayList;
Please help me to get the system's IP address,If we cannot able to get means so please mention me. Because I'm new to android.
I'm using android 1.6 .
There is server side application in the windows xp system. That application is a windows service which is developed by C# .net.
That windows service listen to some port such like 234,etc.If some data comes to port then it will process the data and send response through that port.
In android the android application is send the data to the windows service via socket.
The android phone is USB tethered to the system in which windows service is running.Then system assume android phone is modem and additional IP address is generated for the system.This ip address is dynamically generated when the android phone is tethered.
For data transfer form mobile to system via socket .I will need to give the ip address of the system (after tethered) in my android coding.
If there is any method in android coding to get this IP address.
All are please give your ideas on regarding this.
Its not possible to find IP address created in PC from android after tethering. There is no API or other way to find it.
If you use InetAddress , it will return 192.168.42.129 - which is a DHCP address created by USB Tethering. It wont help you to communicate.
The other way is to scan the list of IP. USB Tethering will create ip ranging for 192.168.42.1 to 192.168.42.255 . You can write a simple scanner to find which one is active. But it will take some time.