The script is set to display 'No connection' after a pretty short 3-second timeout. Feel free to increase that at the line in the script after the comment "# CHANGE THE DELAY HERE…". Just change the number '3' to something longer (the number = seconds). Alternatively, just keep hitting the 'Try Again' button when the script runs as necessary.
property theNext : ""
property theNetwork : ""
property theRouter : ""
property theLocalNode : ""
on getIP()
try
set myTemp to do shell script "mktemp -t txt"
# CHANGE THE DELAY HERE…
delay 3
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
on getCopyItem()
try
set theList to {"Router", "Local IP", "External IP"}
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
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", "Try Again"} cancel button {"OK"} with title "Your IP addresses" default button "Try Again"
set theNext to the button returned of the result
return result
end userInfo
repeat
try
getRouter()
getIP()
getLocalNode()
userInfo()
if result = "Try Again" then
getIP()
else if theNext = "Copy" then
getCopyItem()
exit repeat
end if
on error
exit repeat
end try
end repeat