How to get the peer IP address of other devices

WifiP2pDevice only provides MAC address. http://developer.android.com/reference/android/net/wifi/p2p/WifiP2pDevice.html

I want to get the IP address (but not the MAC address) of other devices after requestPeers (). How can I do that?

+3


source to share


2 answers


There is a way to achieve this ...

Adding Network Service Discovery (NSD)

to your app allows your users to identify other devices on the local network that support the services your apps request. This is useful for a variety of peer-to-peer applications such as file sharing or multiplayer games.

first you need to do

1. Register your service on the network

2. Discovery of services on the network



3. Connecting to services on the network

4. Unregister your service when you close the app

after the completion of 3 no points your application receives detailed information about services including IP address

and port number

. That's all you need to create your own network connection to the service.

Take a look at the details (including sample app). click . second link .. click

+2


source


WifiP2p automatically assigns an IP address after connecting a device in a group. Basically, the owner of the group acts as a DHCP server and assigns IP addresses to all other partners in the group and GO gets GO_IP = 192.168.49.1

.

Assign the GO role so that whenever a new device connects, send it a hashmap of the MAC address versus IP by reading from the file /proc/net/arp

. Now when you want to send a file or message to a MAC address, read its IP address from this hash file. But peers can only send a message to GO, so you need to assign the GO role if the message is sent to an IP other than GO_IP, then forwards it to the appropriate device.



Let me know if you find any problems with this solution.

+2


source







All Articles