I’m trying to write a script here to check the “wake” state of a specific computer on the network.
Since I don’t want to ping someone else’s computer, I’m testing on my own computer. But no matter how active my computer is, the script returns FALSE. In addition, the script runs TERRIBLY LONG.
My request for help is:
Is there an efficient method to accomplish this simple task?
(instead of my stupid method):
on subPing(IPAddress) -- string parameter
try
do shell script "ping -c 5 " & IPAddress
return true
end try
return false
end subPing
set publicIPAddress to word 25 of (do shell script "curl checkip.dyndns.org")
subPing(publicIPAddress) --> false ?????
Also, it would be interesting to know which script is the most efficient (in terms of speed) for a particular task:
Get the external (public) IP address of my computer
You could reduce the number of pings you send from 5 to 1—that should make the script approximately 5 times faster. Although bear in mind that you’re not currently pinging your machine: you’ve retrieved your public IP address, which means you’re essentially pinging your router.
I use https://api.ipify.org to obtain my WAN IP. It offers a multitude of formats, the default being to return just the IP address in plain text, which saves you from having to do any string manipulations. But I also noticed that checkip.dyndns.org returned a different result to every other IP service I tried online. I don’t know what’s up with that.
I found this script (above) in an old thread on our site. There it is just offered to check the wakefulness of a remote computer.
I 1) suspect that it does not solve the problem, 2) it is also slow.
I’ll give a concrete example of my testing:
set public_IP to word 25 of (do shell script "curl checkip.dyndns.org")
--> 62.74.62.214 CORRECT
set public_IP to do shell script "curl 'https://api.ipify.org/'"
--> 62.74.62.214 CORRECT
try
set local_IP to (do shell script "ipconfig getifaddr en0")
on error -- box is not wired, try wireless
set local_IP to (do shell script "ipconfig getifaddr en1")
end try
--> 192.168.43.220 CORRECT
subPing(public_IP) --> FALSE
subPing(local_IP) --> TRUE
subPing("192.168.43.1") --> TRUE (provided my Router IP from Network Preferences)
on subPing(IPAddress) -- string parameter
try
do shell script "ping -c 1 " & IPAddress
return true
end try
return false
end subPing