IP address of networked machines

Could someone on a LAN test this to see if it returns the IP addresses of the connected machines?

set broadcastIP to do shell script "ifconfig en0 | grep broadcast | awk '{print $6}'"
set netIP to do shell script "ping -c 1 " & broadcastIP --change the 1 for more machines --not sure about this part
get word 10 of netIP
--192.168.8.1 = returns my router IP, if no other machine is hooked up

It works for finding the IP of the other machine on my network (my LAN just has 2 machines on it). I’m curious to see if it will return the IPs of more than one connected machine. Thanks…

Sorry Greggo, it does not. Below is the Apple Events Log when I ran it.

Script “untitled 4” started
tell current application
do shell script “ifconfig en0 | grep broadcast | awk ‘{print $6}’”
→ “10.1.255.255” --++ this is our router +±-
do shell script “ping -c 1 10.1.255.255”
→ "PING 10.1.255.255 (10.1.255.255): 56 data bytes
64 bytes from 10.1.35.15: icmp_seq=0 ttl=64 time=1.463 ms

— 10.1.255.255 ping statistics —
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 1.463/1.463/1.463 ms"
end tell
Script “untitled 4” finished

Here is the script result:
10.1.35.15

10.1.35.15 is someone on our lan, but she is not connected to my computer, nor did it show the computer(s) that were connected.


Ross

Thanks Ross, that’s what I needed to know. ;¬)

Greg, it doesn’t tell you anything about whether you are connected to them or vice-versa (connected = mounted volume in AppleShare?). It does, however, show other valid IP addresses. When I ran it with “ping -c 2”, it showed both of the other machines’ IP addresses on my little LAN. That is interesting. I’m sure it’s child’s play for the TCP/IP afficionados out there, but I still think it’s good to see. It makes sense, though - you ping the broadcast address, which should hit everything in the subnet…cool.

Are you sure? Normally, the x.x.x.255 address is the broadcast address (and that’s what Greg’s code is asking for), not the router’s address. Mine is 192.168.123.254. I thought routers tended to be either .1 or .254, leaving the .255 to mask a range of 256.

I got the following result when I used “ping -c 2”:


"PING 192.168.123.255 (192.168.123.255): 56 data bytes
64 bytes from 192.168.123.181: icmp_seq=0 ttl=64 time=0.744 ms
64 bytes from 192.168.123.254: icmp_seq=0 ttl=64 time=2.074 ms (DUP!)
64 bytes from 192.168.123.166: icmp_seq=0 ttl=64 time=3.684 ms (DUP!)
64 bytes from 192.168.123.181: icmp_seq=1 ttl=64 time=0.411 ms

--- 192.168.123.255 ping statistics ---
2 packets transmitted, 2 packets received, +2 duplicates, 0% packet loss
round-trip min/avg/max = 0.411/1.728/3.684 ms"

192.168.123.181 = the iMac
192.168.123.166 = the iBook
192.168.123.254 = the SMC Barricade router

Very cool!

Kewl, thanks Krioni. I’m using the broadcast IP from en0 to ping the LAN in an effort to get the IP addresses of machines that are listed – my bad for using a misnomer of connected – Anyhow, the IPs seem to be available unless the machine has been powered down or unplugged from the network, in which case the IP will be dropped from the table – sleep has no effect as the machines IPs are still in the table and therefore still accessable via a womp. The trick is setting the numeric value of ping -c [1 thru infinity] to the number of machines you want to see. Ross’s response led me to believe it was working to some extent but I think I may have misinformed him of the intent. What I was most curious about was whether it produced a readable output or not.

PS: It will not, by design, return the parent machines IP address, just the machines listed in the table.

Ross, I forgot to ask you if you had changed the ping counter to a number larger than 1. I noticed in your result that it was still set to 1 ping, hence the single IP returned. Try increasing it to maybe 5…

do shell script "ping -c 1 10.1.255.255"
-->change ping -c 1 to something larger

Thanks again…

Greggo, I tried setting it to 5. Here is the Event Log:

Script “untitled 1” started
tell current application
do shell script “ping -c 5 10.1.255.255”
→ "PING 10.1.255.255 (10.1.255.255): 56 data bytes
64 bytes from 10.1.35.85: icmp_seq=0 ttl=64 time=1.682 ms
64 bytes from 10.1.1.2: icmp_seq=0 ttl=60 time=2.379 ms (DUP!)
64 bytes from 10.1.201.1: icmp_seq=0 ttl=255 time=4.843 ms (DUP!)
64 bytes from 10.1.35.85: icmp_seq=1 ttl=64 time=1.281 ms
64 bytes from 10.1.35.153: icmp_seq=1 ttl=60 time=1.564 ms (DUP!)
64 bytes from 10.1.1.7: icmp_seq=1 ttl=60 time=1.944 ms (DUP!)
64 bytes from 10.1.35.11: icmp_seq=1 ttl=255 time=2.133 ms (DUP!)
64 bytes from 10.1.1.6: icmp_seq=1 ttl=60 time=2.418 ms (DUP!)
64 bytes from 10.1.201.1: icmp_seq=1 ttl=255 time=3.582 ms (DUP!)
64 bytes from 10.1.35.34: icmp_seq=1 ttl=255 time=147.312 ms (DUP!)
64 bytes from 10.1.35.85: icmp_seq=2 ttl=64 time=1.361 ms
64 bytes from 10.1.35.153: icmp_seq=2 ttl=60 time=1.686 ms (DUP!)
64 bytes from 10.1.1.7: icmp_seq=2 ttl=60 time=2.183 ms (DUP!)
64 bytes from 10.1.1.6: icmp_seq=2 ttl=60 time=2.514 ms (DUP!)
64 bytes from 10.1.201.1: icmp_seq=2 ttl=255 time=3.309 ms (DUP!)
64 bytes from 10.1.35.12: icmp_seq=2 ttl=255 time=3.459 ms (DUP!)
64 bytes from 10.1.35.85: icmp_seq=3 ttl=64 time=1.361 ms
64 bytes from 10.1.35.155: icmp_seq=3 ttl=60 time=1.694 ms (DUP!)
64 bytes from 10.1.35.99: icmp_seq=3 ttl=255 time=1.768 ms (DUP!)
64 bytes from 10.1.1.7: icmp_seq=3 ttl=60 time=2.002 ms (DUP!)
64 bytes from 10.1.1.6: icmp_seq=3 ttl=60 time=2.42 ms (DUP!)
64 bytes from 10.1.201.1: icmp_seq=3 ttl=255 time=42.432 ms (DUP!)
64 bytes from 10.1.35.152: icmp_seq=3 ttl=64 time=264.242 ms (DUP!)
64 bytes from 10.1.35.85: icmp_seq=4 ttl=64 time=1.311 ms

— 10.1.255.255 ping statistics —
5 packets transmitted, 5 packets received, +19 duplicates, 0% packet loss
round-trip min/avg/max = 1.281/20.87/264.242 ms"
end tell
Script “untitled 1” finished

Krioni, you were correct. It was getting late on a friday at work. the router’s address is actually 10.1.254.254


Ross Higgins