I am now searching for some opinions on how to create a script that will ping IP’s from an Excel page list.
If the IP does not respond to the ping ignore it and move to the next once the IP responds, send a “shutdown -r now” command to it and move to the Next.
I researched here and in other websites but I cannot find anything similar…
This is how far I have gotten…
tell application “Finder”
delay 0.5
set ipFromList to ? – How can I define variable to pick an ip from the excel list?
set noResponse to “false”
set theIP to ipFromList
try
set thePing to do shell script “ping -c 2” & " " & theIP as text & “; echo -n”
on error
set noResponse to "true"
end try
if noResponse ≠"true" then
end if
serverRespondsToPing("www.google.nl")
on serverRespondsToPing(hostname)
return (do shell script "ping -o " & quoted form of hostname & " >/dev/null ; echo $?") = "0"
end serverRespondsToPing
This will provide the solution for getting all of your ip’s saved as a variable:
tell application "Microsoft Excel"
activate
try
open "/Path/to/file/iplist.xls" --Amend "Path/to/file/" to point to your xls file containing list of ip's
end try
tell document "iplist.xls"
tell sheet 1
set ipFromList to get value of range "a1:a70" -- set your variable 'ipFromList' to ips listed in Excel (presuming they are within the range A1 to A70)!!
end tell
end tell
close active workbook saving no
end tell
repeat with i from 1 to number of items in ipFromList
set thisIP to item i of ipFromList
try
set thePing to do shell script "ping -c 2 " & thisIP as text & "; echo -n"
set noResponse to "false"
on error
set noResponse to "true"
end try
if noResponse ≠"true" then
-- send your command (I presume using ARD) ?
end if
end repeat
As mentioned within this script, I presume you will send the ‘shutdown’ command using ARD.