1

I have to find nearby wireless networks along with their IP and MAC addresses. I am using the following piece of code to scan the networks, but I didn't find any way to get the IP addresses of the available networks.

CWInterface* wifi = [[CWWiFiClient sharedWiFiClient] interface];
NSError *err = nil;
NSSet *networksSet = [wifi scanForNetworksWithName:nil error:&err];
NSArray *allNetworks = [networksSet allObjects];
for (CWNetwork *network in allNetworks) {
    NSLog(@"SSID : %@",network.ssid);
    NSLog(@"BSSID : %@",network.bssid);
}

This can be done using the CoreWLAN.framework provided by Apple, but how can I get the details of other wireless networks?

Simon
  • 3,667
  • 1
  • 35
  • 49
Vijay Yadav
  • 511
  • 5
  • 14

1 Answers1

2

The MAC address as you are probably aware is the same thing as the network's BSSID. Regarding IP addresses I think you are out of luck, and probably should not be thinking of a network as having an IP address. Devices on the network has IP addresses, including routers, DHCP servers etc., and the access point might have one or more IP addresses on any networks it's part of, but the network itself does not necessarily have an IP address.

Assuming that it is a router IP address you are looking for I would suspect you have to connect to each network before being able to retrieve it. The WLAN also does not as far as I know advertise any IP addresses outside of the network, as that is simply of no use to devices outside of the network. It's only once a client connects to the WLAN that the IP address of a router or DHCP server has any meaning. I would suspect it is also technically possible to have a WLAN without any devices connected at all.

Simon
  • 3,667
  • 1
  • 35
  • 49
  • Thanks for the answer @Simon. I have a small question Is it technically possible to get Router IP without connecting? Also can you tell me how to get Router IP after connecting to it, I am following this [get wifi router address](http://stackoverflow.com/questions/4872196/how-to-get-the-wifi-gateway-address-on-the-iphone). Will it help – Vijay Yadav Apr 29 '15 at 05:39
  • As far as I'm aware it is not. I might be mistaken, but my understanding is that asking a WLAN for an IP address is analogous to asking the cables in a wired network for one. Imagine for example an encrypted network, you wouldn't expect that to give out any details outside of the network, right? While I wouldn't rule out the possibility that WLANs could somehow report its router IP to potential clients for network identification purposes, my best bet would be to connect first. For that purpose the SO question you linked should provide you with a good starting point I think. – Simon Apr 29 '15 at 06:00