2

I would like to do a scan in a LAN network to find devices linked. I'm developping an app in IOS for IPAD How do I do???

Marcin Koziński
  • 10,835
  • 3
  • 47
  • 61
FabioN1975
  • 45
  • 1
  • 1
  • 3
  • MMLanScan crashes very frequently. whenever you scan the network, it crashes. specially if you scan 2-3 times in a single shot. It will crash – nimisha Jul 10 '19 at 10:01

4 Answers4

15

Because those are mobile devices I will assume you want to find devices on a wireless network. Theoretically, since wifi uses shared medium for communication, you can passively listen for traffic flowing through the network and collect data about client without sending any packets. This is something that is commonly referred to as a promiscuous mode. In practice there is 99% chance that the network adapter driver will allow you only to get traffic destined for your MAC address. In that case you will need to resort to actively scanning the network subnet which is not 100% accurate and depending on how the network is implemented can be considered as a possible attack.

The simple way of scanning is sending ICMP requests (ping) to every IP address in the subnet and collecting data from those who send back the echo reply. This is not reliable because some hosts won't respond to ICMP echo request even if they are active. First thing you need is to find out your own IP address and the subnet mask, and calculate the range of possible addresses in your subnet. The range is obtained by using logical AND operator where operands are binary values of your IP address and subnet mask. This is an example from the program that calculates this for typical 192.168.1.1 subnet with 255.255.255.0 subnet mask (192.168.1.1/24 in CIDR notation):

Address:   192.168.1.1           11000000.10101000.00000001 .00000001
Netmask:   255.255.255.0 = 24    11111111.11111111.11111111 .00000000
Wildcard:  0.0.0.255             00000000.00000000.00000000 .11111111

Network:   192.168.1.0/24        11000000.10101000.00000001 .00000000
Broadcast: 192.168.1.255         11000000.10101000.00000001 .11111111
HostMin:   192.168.1.1           11000000.10101000.00000001 .00000001
HostMax:   192.168.1.254         11000000.10101000.00000001 .11111110

Then you would iterate through the range and ping every address. Another thing you can consider is listening for broadcast traffic such as ARP and collecting some of the information that way. I don't know what are you trying to make but you can't get many useful information this way, except for vendor of a host's network adapter.

pajaja
  • 2,164
  • 4
  • 25
  • 33
  • Hi, In my app I found network class for example 192.168.1.xxx. In this class (from 192.168.1.0 to 192.168.1.255) I must find all IP assigned from the router and then I would like to do "ping" to find some server devices that they are in the network but i don't know the IP – FabioN1975 Jul 31 '13 at 06:55
  • Unless you have access to the router you can't know for sure which IPs are assigned. Also if you ping the IP you will only find out if the host with that address is alive and responding to ICMP requests. If you want to find specific server on the network and you know which service that server is providing, you can check if the host with some IP is accepting connections on specific port that corresponds to the type of service it is serving. If you successfully connect to that port it can be indication that you found the server you were looking for. – pajaja Jul 31 '13 at 07:07
  • I am connected ( with my app ) to the router and I'm looking for a simple method to do a scan of all devices connected in the same router – FabioN1975 Jul 31 '13 at 17:34
  • When i said 'access to the router' i meant management access so you can pull the dhcp lease table for example. If not, the simplest way is the one i already described above. – pajaja Jul 31 '13 at 17:56
  • just because there isn't a "simple method" to do the scan doesn't mean that there shouldn't be at least an up vote for this great answer! – Allen Zeng Aug 28 '13 at 23:30
10

Check my LAN Scan on Github. It does exactly what you want.

Mongi Zaidi
  • 1,043
  • 10
  • 15
  • Is it possible to detect the device type, e.g. printer, ios device, media player? – aparesidam Oct 07 '14 at 16:30
  • Yes it is possible @aparesidam . In fact that was the reason behind developing LAN Scan. – Mongi Zaidi Nov 06 '14 at 09:01
  • This works really great!!! I would like to find the Device type!!! Can you help me on this?? – vensan Feb 19 '15 at 10:34
  • Does it work on Simulator also? Well in my case, not working. Even if I keep pressing on refresh, it show any devices. Also, is it based on pinging all devices? Not all devices respond to ping. – avi Apr 27 '15 at 07:16
  • @avi , it has a problem detecting the simulator ip address. For testing on a simulator you have to uncomment these lines in ScanLan.m file //This is used to test on the simulator //self.localAddress = @"192.168.1.8"; //self.netMask = @"255.255.255.0"; You will have to change them with the ip address and netmask of your mac. – Mongi Zaidi Apr 27 '15 at 11:07
  • Can I find details of the specific device that is connected with my wifi by selecting it? If yes then how can I do this? – Nirmit Dagly Aug 31 '15 at 12:19
  • Does this work for all the possible private IP address ranges? –  Nov 04 '15 at 04:35
  • Why not look into the code before asking these questions? Nobody will answer you that. – Daniel Jun 11 '16 at 03:10
  • 1
    without understanding much about iOS or Swift, I'm wondering if this library is also compatible with OS X? – Hendra Anggrian Jun 20 '16 at 11:39
  • @Mongi Zaidi This repo does not work in Starbucks. Do you know the reason? I works fine in my home LAN. I assume Starbucks is using LAN as well right? – YU FENG Sep 22 '19 at 16:26
5

I recently used MMLANScan that was pretty good. It discovers IP, Hostname and MAC Address.

netcyrax
  • 1,079
  • 1
  • 13
  • 27
4

Bonjour have been around since 2002, have a look at it!

I mean, just look at their current tagline:

Bonjour, also known as zero-configuration networking, enables automatic discovery of devices and services on a local network using industry standard IP protocols. Bonjour makes it easy to discover, publish, and resolve network services with a sophisticated, yet easy-to-use, programming interface that is accessible from Cocoa, Ruby, Python, and other languages.

CodeReaper
  • 5,988
  • 3
  • 35
  • 56
  • Does Bonjour requires any code running on local devices also? or does it work out of box? – avi Apr 27 '15 at 07:20
  • @avi It requires that the devices on the network are discoverable presumably by running some sort of code, but not code that you would have to make/maintain/start/install or whatnot. It should Just Work® :) – CodeReaper Apr 27 '15 at 08:04
  • Bonjour will only work if your router supports multicasting. –  Nov 04 '15 at 04:33