3

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

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

user2301281
  • 757
  • 2
  • 12
  • 27
  • Hi @user2301281 are you trying to get **"Group Owner IP address"** from `onConnectionInfoAvailable(final WifiP2pInfo info)` ?? http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html – Hariharan Gandhi May 27 '15 at 09:30
  • Possible duplicate of [How to get each device's IP address in Wi-Fi Direct scenario?](http://stackoverflow.com/questions/10053385/how-to-get-each-devices-ip-address-in-wi-fi-direct-scenario) – patryk.beza May 17 '16 at 12:48

2 Answers2

2

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 app requests. This is useful for a variety of peer-to-peer applications such as file sharing or multi-player gaming.

first you need to do

1.Register Your Service on the Network

2.Discover Services on the Network

3.Connect to Services on the Network

4.Unregister Your Service on Application Close

after complete 3 no points your application receives detailed service information including an IP address and port number. This is everything you need to create your own network connection to the service.

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

Tanim reja
  • 2,120
  • 1
  • 16
  • 23
2

WifiP2p auto assigns the IP once the device is connected in the group. Basically the group-owner acts as a DHCP server and assigns IPs to all the other peers in the group and GO gets the GO_IP = 192.168.49.1.

Assign a role to GO that whenever new device connects send it the hashmap of 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 from this hashmap. But the peers can send the message to GO only so you need to assign the role to GO if the message is sent for an IP other than GO_IP then it forwards it to the respective device.

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

unrealsoul007
  • 3,809
  • 1
  • 17
  • 33
  • I look for your suggestion in here, http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html But I don't have idea how to get the GO_IP from onConnectionInfoAvailable(final WifiP2pInfo info). I also can't find the hashmap that you mention. Can you elaborate more or any link can refer for? Thanks. – user2301281 May 16 '15 at 00:33
  • If you read the system file `proc/net/arp`, you will get a list of devices currently connected to your hotspot. So when people connect to you read this file and parse it to get HW Addresses(MAC Addresses) and IP addresses. – unrealsoul007 May 16 '15 at 18:13