The script retrieves the IP address from https://ident.me then connects to the Google Sheets API and adds the current computer address to the Google Sheet. This simple application was created for Wake On Lan purposes. My ISP assigns a dynamic IP address so waking up the computer remotely may not necessarily work in this case. However, having a list of the last IP used seems possible, at least for the lease time period set by the ISP. Finally, a script trigger was set using Task Scheduler, which launches the application when the sleep button on the laptop is clicked.
In order to set up Wake On Lan on your computer, you need to:
- Change the settings for the network card and enable wake on lan option
- In many cases, you should also go to the BIOS and activate such functionality from there as well
- Add port forwarting to the router on port
3389- If you want to not only start your computer remotely but also use it via Remote Desktop Connection, you need to set Port Forwarting on your router. When you use a remote desktop client to connect to your personal computer (PC), you are establishing a peer-to-peer connection. The host (your PC) must therefore be directly accessible to you. If you want to connect to your system from outside the network it is running on, you must somehow enable the access.
- Please be mindful when enabling port forwarding on 3389 as your computer is
- getting exposed to the external network and might be a target of hackers attack!Also please check if you have enabled Remote Desktop Connections Enable Remote Desktop on your PC
Some resource for Wake On Lan instruction: How to activate Wake On Lan in Windows 10 and 11
Explenation of risk related to the 3389 port forwarding: Remote Desktop Penetration Testing
I think here ia a good explenation what needs to be enabled and configured to have Google API working: Enable Google Sheets API Remember that you need two APIs enabled: Google Sheets and Google Drive. This is how it is reflected in the code:
SCOPES = ['https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive']The final step is to configure the Task Scheduler. All you need to do is create a new task and add a trigger.
- In
Program/Scriptinput paste the exact path to the python.exe application on your computer. You can find it easliy by typing incmdcommand:
where python- In
Add arguments (optional)input provide the name of the file with the python script to run - In
Start in (optional)input provide the path to the folder with the script
As a trigger for a task select On workstation lock, so each time you press power button on the laptop (sleep mode) you script will be triggered. Setting the Windows Task Scheduler to run on Kernel Power sleep event 42 was failing due to some unexpected error.

Copyright © 2023, Andrzej Strzala.


