leopard breaks this method. anyone know another way?
anyone?
This won’t get you a list for your script but it will let you pick one. The command has some options in the standard additions dictionary too.
choose URL
I also have this in my library… in case it’s what you’re looking for.
property theArp : "#!/bin/sh
/usr/sbin/arp"
-- get your internal ip
try
set myIP to item 1 of getInternalIPs()
on error
display dialog "You do not seem to be connected" buttons {"OK"} default button 1 with icon stop
return
end try
-- find your subnet from your ip
set {tid, text item delimiters} to {text item delimiters, "."}
set subNet to text items 1 thru 3 of myIP as text
set MM to text item -1 of myIP as text
set text item delimiters to tid
-- ping your subnet
set p to (do shell script "ping -c3 " & subNet & ".255")
set text item delimiters to return & "64 bytes from " & subNet & "."
set Nup to text items 2 thru -1 of p
set IPisUp to {}
set text item delimiters to ":"
repeat with aLine in Nup
tell (text item 1 of contents of aLine) to if it is not MM and it is not in IPisUp then set end of IPisUp to it
end repeat
set text item delimiters to tid
set tellMe to "The following IP's are now answering broadcast pings on your subnet. The IP of this machine " & myIP & " has been excluded" & return & return
repeat with anIP in IPisUp
set preTellMe to {}
set preTellMe to subNet & "." & contents of anIP
do shell script "sh -c " & quoted form of (theArp & space & preTellMe)
set res to the result as Unicode text
set resArp to {}
repeat with w from 1 to number of words in res
set text item delimiters to space
try
set this_item to text item w of res
-- log this_item
end try
set end of resArp to this_item
if this_item = "at" then
set prev_word to (w - 2)
set myHost to text item prev_word in res as text
--log myHost
set next_word to (w + 1)
set interface_word to (w + 3)
set theMac to text item next_word in res as text --if you wanted MAC addresses, say for Wake On Lan
set theInterface to text item interface_word in res as text
if myHost = "?" then
set tellMe to tellMe & return & "Name: " & "\"?\"" & return & "IP Address: " & preTellMe & return & theInterface & ": " & theMac & return
else
set tellMe to tellMe & return & "Name: " & myHost & return & "IP Address: " & preTellMe & return & theInterface & ": " & theMac & return
end if
end if
set text item delimiters to tid
end repeat
end repeat
display dialog tellMe --with icon 1
(*Note: SP2 for WinXP automatically disables answering broadcast pings unless the instruction "set multicastbroadcastresponse ENABLE" is entered in each by an administrator of the machine.*)
to getInternalIPs()
set intIPs to {}
repeat with i from 0 to 4
try
set ip_internal to do shell script ("ipconfig getifaddr en" & i)
set end of intIPs to ip_internal
end try
end repeat
return intIPs
end getInternalIPs
hmm, i like the choose URL thing, i think i may use that. but is there anyway i can just get the IP of the chosen computer with out the afp:// and the port number at the end. i could use text item delimiters, but i’ terrible at them. thanks.
set theURL to choose URL
set text item delimiters to "afp://"
set stepOne to item 2 of (text items of theURL)
set text item delimiters to ":548"
set theIP to item 1 of (text items of stepOne)
set text item delimiters to ""
theIP
cool, thanks. is it always port 548, or is that just the default? can it be changed?
afp is always 548 unless you change it somehow… but just to be safe you can remove the “548” and just use the colon as the 2nd text item delimiter. It should work fine with just the colon. And just to be safe on the first part you can use “://”. So here’s an altered script…
set theURL to choose URL
set text item delimiters to "://"
set stepOne to item 2 of (text items of theURL)
set text item delimiters to ":"
set theIP to item 1 of (text items of stepOne)
set text item delimiters to ""
theIP
yup, it works. thanks for the help.
one more question. Was the choose URL thing added in leopard or is it available in tiger aswell? thanks.
I’m pretty sure it goes back many OSX versions, even 10.2 and maybe more.
hmm, i wonder why nobody mentioned it in this thread.
thanks again for the help.
You’re welcome. Just open the standard additions dictionary and search for “choose”. There’s a bunch of them…
yeah, i just did that, there’s a lot of cool stuff in there i’ve never seen.