Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get the list of interfaces and IP addresses, use <code>getifaddrs()</code>.</p> <p>Search for interfaces with <code>ifa_addr-&gt;sa_family == AF_INET</code></p> <p>The IP address is in <code>sin_addr.s_addr</code>.</p> <p>You can then use <code>gethostbyaddr()</code> to look up the DNS name for that IP address.</p> <p><strong>Update:</strong></p> <p>It was pointed out to me that the OP was probably asking about discovering other hosts, rather than the addresses of interfaces on the local machine.</p> <p>There is no reliable way to discover other machines on the local area network, but there are a couple of tricks.</p> <ul> <li><p>Ping method: Use the ping utility (or a programatic equivalent) to ping the local broadcast address, then see who responds. The broadcast address can be found by listing the interfaces as shown above. I believe ICMP does not require root access under OSX. Note that many systems may have ICMP ping disabled or firewalled, so you will only get responses from the non-stealth ones.</p></li> <li><p>ARP method: Check the system ARP cache to see what IP addresses have been recently active. This will only show systems which have broadcast packets on the same network segment in recent minutes.</p></li> </ul> <p>Both methods can be blocked by firewalls, routers, and even switches, so the exact borders of the "LAN" can be pretty narrow. Both methods can be implemented programmatically, but it might be simpler and more portable to just call out to the command line <code>ping</code> or <code>arp</code> commands.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload