Use Python to Cycle Your IP with HMA VPN Software and Windows Automation
by Mike Levin
Thursday, August 11, 2022Wow wee! This is not a nut I thought I’d crack. Actually, someone else cracked the nut and it was October of 2021. I wish I was staying on top of this topic to spot it sooner, but automating stuff on the Windows desktop isn’t too hard using pywinauto. I actually try to avoid it because it’s a lot like web browser automation, but without the cross-platform advantage and ability to run it headlessly on a server. But sometimes you just have to automate Windows… in order to get a new IP from your HMA VPN software, LOL! Read into that whatever you want, but I am an SEO (search engine optimizer) after all. The solution this problem is here:
https://stackoverflow.com/questions/69705923/control-windows-app-hma-vpn-using-pywinauto
…and the actual code that he posted is:
from pywinauto import Desktop,Application
vpn_app = Application(backend="uia").start('C:\Program Files\Privax\HMA VPN\Vpn.exe')
dialog=Desktop(backend="uia").HMA
panel0=dialog.Pane
# Command to connect / disconnect the VPN: connect_button.click()
connect_button=panel0.ConnectButton
# Command to change the IP address: changeIP.click()
changeIP=panel0.Button5
# Check VPN state:
# 0 if disconnected
# 1 if connected
print(connect_button.get_toggle_state())
# Command to connect / disconnect the VPN: connect_button.click()
connect_button=panel0.ConnectButton
connect_button.click()
# Command to change the IP address: changeIP.click()
changeIP=panel0.Button5
changeIP.click()
# Check VPN state:
# 0 if disconnected
# 1 if connected
print(connect_button.get_toggle_state())