alex-v
alex-v

Reputation: 83

How to get a list of IP of all devices on the LAN?

We used the library SimplePing, but multiple challenges of our network scanner sometimes some devices were not found. ie This scanner does not work reliably. Prompt another library or a more reliable algorithm for IOS?

Perhaps I need to write a ping using sockets:

socket(AF_INET,SOCK_DGRAM,IPPROTO_ICMP)

But what further code?

Upvotes: 2

Views: 607

Answers (2)

Rob Napier
Rob Napier

Reputation: 299265

Not all devices respond to ICMP PING (which is what you're using). Are there specific devices that are never discovered? If so, do they respond to the "ping" command?

If it is more erratic, then you need to start with network traces (most commonly using wireshark). You need to determine if the pinged machine received the ping, and separately whether your device received the response. You will generally want to build a small, private network for this so you can control the hardware.

Generally speaking, it is easier to initially develop this kind of code in the simulator rather than a device. Does it work more reliably in the simulator?

Are you receiving errors? Are there firewalls involved? (Firewalls often swallow ICMP without generating errors.)

You're going to need a lot more specific diagnostic information beyond "does not work reliably." You need to know exactly which pieces do and don't work. Did you send the packet? Did they receive the packet? Did they send the response? Did you receive the response? Without those basic data, it's very hard to troubleshoot networking.

Upvotes: 1

Alexander Perechnev
Alexander Perechnev

Reputation: 2837

You can see the implementation of ping utility in FreeBSD source code: https://svnweb.freebsd.org/base/release/10.1.0/sbin/ping/ping.c?view=markup

Don't be afraid to read source codes of existing implementations for any platforms, because they all use the same basis, and your app will not be an exception.

Btw, you can compile C-code for your app written in Objective-C.

Update.

And here is a good explanation about how to use sockets: http://www.linuxhowtos.org/C_C++/socket.htm

Upvotes: 1

Related Questions