Function To Interact With A VPN Software

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Newbie19
Posts: 1
Joined: 23 Feb 2018, 19:33

Function To Interact With A VPN Software

23 Feb 2018, 19:53

Greetings everyone. :dance:

English is not my native language, so I would like to apologize for my lack of fluency in English.

I do not know if my question has already been answered in another topic.

I am a Newbie and I ask all of you to have patience with me. :D

My question is this.

I need to create a program that performs the following functions.

Start an external VPN software and when the VPN changes the IP of my computer, run the browser and enter a specific site. Only that.

HOWEVER, VPN software when executed takes a random amount of time to find a network node and change the IP address of my computer.

What I mean is that the time it takes for the VPN to find an IP address ranges from 2 minutes to 8 minutes.

And the browser can only be executed AFTER the VPN changes my IP address (which will depend on external factors that are out of my control such as my ISP's speed, availability of a network node, speed of my computer)

So I need to create source code with a latency time based on the VPN software itself and NOT based on a predetermined and fixed time.

To solve this problem I DO NOT WANT TO USE A FIXED WAIT TIME.

Sleep, 6000 (I DO NOT WANT TO DO THIS, I DO NOT WANT TO DEFINE A FIXED NUMBER FOR THE Sleep FUNCTION)

The sleep time defined by the Sleep function must reference some process of the VPN software, and can not be defined arbitrarily, fixed and predetermined.

Because in one day the VPN can take 2 minutes to change my IP and another day the VPN can take 8 minutes to change my IP.

Before someone tells me, switch VPN, choose other VPN software, or ask me to do this manually, it is very important that you understand the core of the problem.

I want to create programs with functions that execute tasks based on the time a process takes to be terminated by the processor and NOT based on a fixed time arbitrarily chosen. This is the main issue. This is the crux of the problem.

So the question is, what would the source code look like?

What is the function I should use for this purpose?

What parameters do I need to pass to this function?

How would the source code of this program look in a hypothetical example?

If you have read through to the end I would like to apologize to you because I understand that my text must have gotten extremely annoying and full of unnecessary phrases that do not make the slightest sense but I did my best to make my text clearer possible.
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Function To Interact With A VPN Software

23 Feb 2018, 23:31

I'm an ahk newbie but does your vpn notify you when you've connected. Also is it in your background or is it an application? Does the application change a bit so you can
use imagesearch to determine whether it has connected? Or pixel/image search is not an option at all?
I am your average ahk newbie. Just.. a tat more cute. ;)
gregster
Posts: 8992
Joined: 30 Sep 2013, 06:48

Re: Function To Interact With A VPN Software

24 Feb 2018, 00:01

Yeah, reading out the status/some information from your VPN software might be a solution - the difficulty (and reliability) probably depends on the actual software you use.

But if I understand the problem correctly, I would probably just check - let's say every 30 seconds - the actual IP address via some website that reports it in simple text format (for easy parsing), and then act as soon as it changes.
Commands like SetTimer, Run, If and UrlDownloadtoFile (or better, one of the UrlDownloadtoVar user functions from the forum) are probably useful for that; and of course, some website like http://myip.dnsdynamic.com/ that just gives you a plain IP and nothing else to trim.

Edit: oops. the links to the command docs seem to be broken. I will report on forum issues. Meanwhile, look up the commands here: https://autohotkey.com/docs/commands/index.htm
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Function To Interact With A VPN Software

24 Feb 2018, 00:22

gregster wrote:Yeah, reading out the status/some information from your VPN software might be a solution - the difficulty (and reliability) probably depends on the actual software you use.

But if I understand the problem correctly, I would probably just check - let's say every 30 seconds - the actual IP address via some website that reports it in simple text format (for easy parsing), and then act as soon as it changes.
Commands like SetTimer, Run, If and UrlDownloadtoFile (or better, one of the UrlDownloadtoVar user functions from the forum) are probably useful for that; and of course, some website like http://myip.dnsdynamic.com/ that just gives you a plain IP and nothing else to trim.

Edit: oops. the links to the command docs seem to be broken. I will report on forum issues. Meanwhile, look up the commands here: https://autohotkey.com/docs/commands/index.htm
Dang that's intelligent. :shock:
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Function To Interact With A VPN Software

24 Feb 2018, 00:33

Are the online documents down or something it's glitched for me (yep looks like they are glitched at the moment. Anyways you can still use the Help file I guess. It's a neat idea I want to try doing this. I know there are good ways to do this but I will try anyway because it's fun. I'm using UrlDownloadToFile and FileRead btw. I'll let you know if I succeed hehe.

Update:
Here's a script that I wrote, it works perfectly for me let me know if it worked. :dance:

Code: Select all

UrlDownloadToFile, http://myip.dnsdynamic.com/, myip.txt
FileRead, originalip, myip.txt
				;save ip when script was launched to originalip

SetTimer, checkip, 10000 ; checks ip every 10seconds, anticipating change. You can change the interval to anything even 1second. 
return

	checkip:
UrlDownloadToFile, http://myip.dnsdynamic.com/, myip.txt
FileRead, newip, myip.txt
				; saves ip to newip


If (newip = originalip)
return
				;if ip has not changed, return.
	Else 
	{
	SetTimer, checkip, off 
	Run, https://www.google.com/ ; change to required website.
	FileDelete, myip.txt
				;if ip has been changed, sets timer off and runs the required website and deletes the unwanted .txt file.
	}
return ; or ExitApp if that is all you want to happen



Esc:: ExitApp


Just make sure there is no myip.txt file, in the path the script is stored in.
I am your average ahk newbie. Just.. a tat more cute. ;)
Appie van Zon
Posts: 1
Joined: 26 Feb 2018, 14:47

Re: Function To Interact With A VPN Software

27 Feb 2018, 02:38

Good morning! I have read and understood your story. But I can not help you (yet) because I'm a newbee myself.
Sincerely,
Appie van Zon

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], haomingchen1998, mikeyww, mmflume, roysubs, scriptor2016, ShatterCoder and 98 guests