Objectives:
I want to create an AppleScript .scpt file that does the following:
-
Accesses a router's webpage (i.e., its IP address).
-
From this webpage, gets the IP addresses that are currently connected to both networks. (By "both networks", I refer to the separate 2.4Ghz and 5.0Ghz wireless networks.)
-
From the webpage, gets the respective Dbm signal strengths of each connected device (i.e., each connected IP address).
Implementation:
I want one AppleScript list
object to contain all of the IP addresses:
- E.g.:
theListOfIPs
contains{"192.168.0.1", "192.168.0.", "192.168.0.3", "192.168.0.4", "192.168.0.5", "192.168.0.6.", "192.168.0.7"}
.
(I do not have the need to differentiate between the IPs that are connected to the 2.4GHz network and the IPs that are connected to the 5.0GHz network. All IPs should simply be contained in theListOfIPs
.)
And, one AppleScript list
object to contain their corresponding signal strengths:
- E.g.:
theListOfTheirSignalStrengths
contains{"0", "-75", "-40", "0", "0", "-63", "-72"}
.
Notes:
-
I would like all of this to be completed "behind the scenes." Unobtrusiveness is really key, because the script will need to periodically check the router's website for network updates.
-
Ultimately, changes to the network status will be written to a .txt log file, and an alert notification will be displayed, when certain conditions are met. I know how to code these components; I need help actually importing the data into the script.
-
Browser of choice: Google Chrome
Background:
I have used the shell command , curl
, before, in order to import the unabridged HTML source code of a given website into an AppleScript, as a text
object. I understand that, sadly, one cannot similarly or conveniently get all JavaScript elements into an AppleScript as a single text object.
Instead, one must get each and every JavaScript element individually, by some identifier, like its id
, class
, tag
, or name
. This makes things more complicated (because you can't simply parse everything in AppleScript).
By using Chrome's Inspect feature, and the Elements pane of Chrome's JavaScript console, I've determined the relevant JavaScript identifiers. The two JavaScript element IDs that contain all IP addresses, as well as their signal strengths, are wifi-24
and wifi-5
.
Can someone teach me how to write the necessary JavaScript code correctly, and then parse the resulting HTML text, to isolate the basic network data that I desire?
Best Answer
Based on the discussions had, this should handle the original scope of the question.
Note: This is example code and does not contain much, if any, error handling. I'll leave that to you since this is only a portion of the overall script, once you put all the other pieces together.
I do have to say that generally speaking, one is not supposed to parse HTML with tools like
grep
andsed
, however, for certain pages, like in this use case, it's pretty safe to do. Although, if it breaks, it's not hard to fix.