1

I want to get all the entries I would normally get via Finder, but using command line. So from this:

Network devices

I want to retrieve at least "celeste-7" and "Time Capsule" (just the label is fine) directly in a bash script or applescript.

Commands like ippfind and dns-sd -B _ssh._tcp . don't show all the devices I see in the Finder, not even half.

Any ideas?

2

You are using the correct dns-sd to discover local services. The problem is you need to search for all the potential items.

Screen sharing, AFP file sharing, SMB file sharing, etc...

Worse, if you have Back to My Mac and iCloud connected devices, not all of them are local, but they are still discoverable from the command line:

If you wanted to pick apart all the ports / protocols you could use the Network Utility to port scan each device you see in you finder sidebar and look for the common ports that are listening.

Apple’s big list of ports and names is here:

I think you’ll get good coverage if you start with remote control, file sharing (VNC/AFP/SMB) though.

0

You can use two commands: ping and arp to get the info that you need.

ping allows you to broadcast to your network and any device that on the network and capable of responding will reply.

Let's assume your network is 192.168.1.0. Broadcast your ping by using the broadcast address 192.168.1.255

$ ping 192.168.1.255 

This will go on forever, so either ControlC or use the -t option to set a timeout. For example, for 20 seconds of pining...

$ ping -t 20 192.168.1.255

You will get a bunch of responses; some of which will be duplicate. This will continue for 20 seconds then stop.

Next, arp to find the names:

$ arp -a

allans-imac.home (192.168.1.12) at a8:20:66:40:5b:10 on en0 ifscope permanent [ethernet]
grace-pc.home (192.168.1.18) at 0:34:f6:5:f7:29 on en0 ifscope [ethernet]
grace-iphone.home (192.168.1.150) at b8:63:3a:14:3e:f7 on en0 ifscope [ethernet]
nas.home (192.168.1.23) at 0:12:43:20:aa:3d on en0 ifscope [ethernet]

That's a truncated sample of the output from my network (names, MACs and IPs randomized for security). As you can see, it includes the hostnames and MACs of devices I have on my network.

Sleeping devices (like my HP printer and my MacBook Pro) didn't respond and aren't in the arp table. Then again, they don't show up in Finder, either.

With the application of grep and awk, you should be able to extract what you need.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .