On Sunday, 23 January 2022 at 06:30:11 UTC, frame wrote:
On Saturday, 22 January 2022 at 20:55:38 UTC, Daren Scot Wilson
wrote:
I don't see any D std.* libraries that do this. Are there a
Dub packages I should look at?
If you really want to this in D without any external app or OS
API you could just ping all possible hosts, see which respond
and then use `getHostByAddr()` to find the hostname.
Another more professional way is to query the ARP protocol,
where you send a packet as broadcast to all interfaces in the
network to find a MAC for a given IP - if any host responses
with a MAC, the host is up.
You have to build the packet data for yourself, there are
examples on the web. The socket to use is family:INET, type:RAW
and protocol:ICMP for ping or RAW for ARP or anything that
isn't listed in D.
As you can see, it's required to test every possible IP out
(except for any other discovery protocols supported by your
network/router). For this reason, any OS does this scan
periodically and caches the result. On UNIX you can just
directly read the file `/proc/net/arp`, no need to use nmap.
I'll try this. Looks more educational. This is a personal
project, a show-off project. Once I'm done with another portion
of it, I'll get onto this. My program will need to scan only
once, not even once per run, since I can stash the results in a
config file, but once whenever the user knows the hardware
devices have changed.