Get the IP address of the Android network interface

I am writing a wifi-direct application for Android. I am trying to make a socket connection to a device. Since the intent function of the owner of the group does not work (it just randomly assigns its appearance), I have to find a way to transfer the IP addresses of clients to the host. The only address I know about is the host device, which is part of the group information object that WifiP2pManager can receive. I know which device is the host and which client, so I can open the socket to connect or try to connect to another.

I need to find a way to transfer the IP address of a Wifi P2P device (Wifi Direct) if the host device is the owner of the group. If the host is the owner of the group, I have no way to connect to the socket on the client. This is a bit confusing, but how it works.

I saw things like getting an IP address from an ARP table, but the ARP table seems to be cleared after a few seconds (like a minute) and on ICS, since the Wi-Fi interface is disabled for Wifi direct I don’t even see anything in arp table.

It seems to me that this should be easy, but I'm not a big Linux user, so I don’t know which file will contain the network interface configurations. Is there any way to get hte IP addresses of network interfaces? Or at least the Wifi P2P interface? (Note: this is not a wifi address. It is similar to the binding address except for Wifi Direct. WifiManager does not return this)

Thank
Mgamerz

+5
source share
1 answer
DhcpInfo dhcpInfo = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE)).getDhcpInfo();
String ipaddress = intToIp(dhcpInfo.ipAddress)

intToIp(int integer) {
        return (integer & 0xFF) + "." + ((integer >> 8) & 0xFF) + "."
                + ((integer >> 16) & 0xFF) + "." + ((integer >> 24) & 0xFF);
    }

The above code should help you get ipaddress ...

to get the IP address of a client that connects to the host through a socket that you can use. clientSocket = this.serverSocket.accept (); clientSocket.getInetAddress ();

+1
source

All Articles