Thursday, August 11, 2022

#1 2022-08-01 11:51:58 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2443

Check if a specific computer on a network is awake

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):

Applescript:


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:

1) Get the external (public) IP address of my computer

Last edited by KniazidisR (2022-08-02 12:00:35 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#2 2022-08-02 12:34:56 am

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 176

Re: Check if a specific computer on a network is awake

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.

Offline

 

#3 2022-08-02 04:02:30 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2443

Re: Check if a specific computer on a network is awake

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:

Applescript:


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

Last edited by KniazidisR (2022-08-02 04:27:21 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)