hallo
I’m new to AppleScript
I tried to play a little with a script for a network application.
the scrip have to scan ip router, PC and external. also scans a range of IPs fixed.
When I run from the script editor works ok. When I turn in the application I get the message “Can’t get end.”
I tried to hang with more end … not found error.
property theNext : “”
property theNetwork : “”
property theRouter : “”
property theLocalNode : “”
on getIP()
try
set myTemp to do shell script “mktemp -t txt”
do shell script “curl -s http://checkip.dyndns.org &> " & myTemp & " &2> /dev/null”
# CHANGE THE DELAY HERE.
delay 4
set extIP to do shell script "sed 's/[a-zA-Z/<> :]//g' " & myTemp
if extIP = "" then
set my theNetwork to "No connection"
else if extIP contains "=" then
set theNetwork to "Can't get IP"
else
set theNetwork to extIP
end if
on error
set theNetwork to "No connection"
end try
end getIP
on getRouter()
try
set oldDelims to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “gateway:”
set theGateway to do shell script “route get default | grep gateway”
set AppleScript’s text item delimiters to oldDelims
set theRouter to the last word of theGateway
on error
set my theRouter to “No connection”
end try
end getRouter
on getLocalNode()
try
set theIP to (do shell script “ifconfig | grep inet | grep -v inet6 | cut -d" " -f2”)
set theLocalNode to the last word of theIP
on error
set theLocalNode to “Can’t get Local IP”
end try
end getLocalNode
end
on getCopyItem()
try
set theList to {“Router”, “Local IP”, “External IP”, “Controller”}
choose from list theList with prompt “Choose an item to copy:”
set myResult to (item 1 of the result)
if myResult = “Router” then
set the clipboard to theRouter
else if myResult = “Local IP” then
set the clipboard to theLocalNode
else if myResult = “Controller” then
set the clipboard to “192.168.200.253”
else
set the clipboard to theNetwork
end if
end try
end getCopyItem
on userInfo()
display dialog "Router: " & theRouter & return & return & "Local IP: " & theLocalNode & return & return & "External IP: " & theNetwork buttons {“OK”, “Copy”, “Scan Retea”} cancel button {“OK”} with title “Your IP addresses” default button “Scan Retea”
set theNext to the button returned of the result
return result
end userInfo
on scan()
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.253"
exit repeat
on error
beep
display alert " Eroare - Controllar cazut"
delay 2
display alert "Controllar - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.254"
exit repeat
on error
beep
display alert " Eroare - Router cazut"
delay 2
display alert "Router - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.2"
exit repeat
on error
beep
display alert " Eroare - SW Principal - Cazut"
delay 2
display alert "SW Principal - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.3"
exit repeat
on error
beep
display alert " Eroare - SW Diamond cazut"
delay 2
display alert "SW Diamond - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.4"
exit repeat
on error
beep
display alert " Eroare - SW Corp Nou Principal - Cazut"
delay 2
display alert "SW Corp Nou Principal - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.8"
exit repeat
on error
beep
display alert " Eroare - SW Etaj 4 AB - Cazut"
delay 2
display alert "SW Etaj 4 AB - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.9"
exit repeat
on error
beep
display alert " Eroare - SW Etaj 5 AB cazut"
delay 2
display alert "SW Etaj 5 AB - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.13"
exit repeat
on error
beep
display alert " Eroare - SW Etaj 4 Corp C cazut"
delay 2
display alert " SW Etaj 4 Corp C - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.14"
exit repeat
on error
beep
display alert " Eroare - SW Etaj 5 Corp C cazut"
delay 2
display alert "SW Etaj 5 Corp C - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 192.168.200.15"
exit repeat
on error
beep
display alert " Eroare - SW Etaj 6 Corp C cazut"
delay 2
display alert "SW Etaj 6 Corp C - Eroare dupa 5 incercari"
if i = 2 then error number -128
end try
end repeat
display dialog "Retea OK. " buttons {"Try Again", "OK"} cancel button {"OK"} default button "OK"
end scan
repeat
try
getRouter()
getIP()
getLocalNode()
userInfo()
if result = “Scan Retea” then
scan()
else if theNext = “Copy” then
getCopyItem()
exit repeat
end if
on error
exit repeat
end try
end repeat
display alert “Super”
end
end