aa2zz6 Posted September 6, 2015 Posted September 6, 2015 I created a SoftEther VPN Client script to change my IP in order to watch my Korean drama's that might be unavailable to the USA. The script runs every half hour to check whether the IP is still activated, and if not, the script will find one. I will post the code below but I wanted to ask if there was an easier, more smarter way to write this. This is made with the image search so if anyone wants the images then I can upload them.expandcollapse popupHotKeySet("{ESC}", "Terminate") #include <ImageSearch.au3> #include <GDIPlus.au3> #include <GuiConstants.au3> #include <MsgBoxConstants.au3> $counter = 0 If launch() Then EndIf If hosted() Then Exit EndIf If gate() Then EndIf If refresh() Then EndIf If addressIP() Then EndIf Do Sleep(3000) agree() $counter = $counter + 1 Sleep(3000) Until $counter = 2 ProcessClose("vpncmgr_x64.exe") ; ----------------------Load Page ------------------------------------- Func launch() MsgBox($MB_SYSTEMMODAL, "VPN", "Launching Program.", 1) $chrome = ShellExecute("C:\Users\Public\Desktop\SoftEther VPN Client Manager.lnk") Sleep(500) WinSetState("[active]", "", @SW_MAXIMIZE) Sleep(500) EndFunc ;==>launch Func hosted() Do MsgBox($MB_SYSTEMMODAL, "VPN", "Hosted.", 1) #include <ImageSearch.au3> #include <GDIPlus.au3> $fileA = @ScriptDir & "\pics\estConnection.png" _GDIPlus_Startup() $hImageA = _GDIPlus_ImageLoadFromFile($fileA) ;this is the firefox icon use something else if you don't have it. $hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA) $x = 0 $y = 0 $result = _ImageSearch($hBitmapA, 1, $x, $y, 20, 0) ;Zero will search against your active screen Sleep(500) If $result > 0 Then ProcessClose("vpncmgr_x64.exe") Exit EndIf Until True EndFunc ;==>hosted Func refresh() Do MsgBox($MB_SYSTEMMODAL, "VPN", "Refreshing.", 1) #include <ImageSearch.au3> #include <GDIPlus.au3> $fileA = @ScriptDir & "\pics\test1.png" _GDIPlus_Startup() $hImageA = _GDIPlus_ImageLoadFromFile($fileA) ;this is the firefox icon use something else if you don't have it. $hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA) $x = 0 $y = 0 $result = _ImageSearch($hBitmapA, 1, $x, $y, 20, 0) ;Zero will search against your active screen Sleep(500) If $result > 0 Then Sleep(1000) ;MouseMove($x, $y) MouseClick($MOUSE_CLICK_PRIMARY, $x, $y, 2) Sleep(3000) EndIf Until True EndFunc ;==>refresh Func gate() Do MsgBox($MB_SYSTEMMODAL, "VPN", "Gate - Opens to list of IP's.", 1) #include <ImageSearch.au3> #include <GDIPlus.au3> $fileA = @ScriptDir & "\pics\connect.png" _GDIPlus_Startup() $hImageA = _GDIPlus_ImageLoadFromFile($fileA) ;this is the firefox icon use something else if you don't have it. $hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA) $x = 0 $y = 0 $result = _ImageSearch($hBitmapA, 1, $x, $y, 20, 0) ;Zero will search against your active screen Sleep(500) If $result > 0 Then Sleep(500) ;MouseMove($x, $y) MouseClick($MOUSE_CLICK_PRIMARY, $x, $y, 2) Sleep(1000) EndIf Until True EndFunc ;==>gate Func addressIP() Do MsgBox($MB_SYSTEMMODAL, "VPN", "Finds an IP.", 1) #include <ImageSearch.au3> #include <GDIPlus.au3> $fileA = @ScriptDir & "\pics\mbps.png" _GDIPlus_Startup() $hImageA = _GDIPlus_ImageLoadFromFile($fileA) ;this is the firefox icon use something else if you don't have it. $hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA) $x = 0 $y = 0 $result = _ImageSearch($hBitmapA, 1, $x, $y, 20, 0) ;Zero will search against your active screen Sleep(500) If $result > 0 Then Sleep(500) ;MouseMove($x, $y) MouseClick($MOUSE_CLICK_PRIMARY, $x, $y, 2) Sleep(1000) EndIf Until True EndFunc ;==>addressIP Func agree() Send("{Enter}") EndFunc ;==>agree Func Terminate() Exit EndFunc ;==>Terminate
computergroove Posted September 6, 2015 Posted September 6, 2015 I would shorten this up quite a bit and use something like https://www.whatismyip.com/my-ip-information/?iref=home and read the state/region and read it into a variable. Much easier and more reliable than imagesearch and you could run it hidden. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
aa2zz6 Posted September 7, 2015 Author Posted September 7, 2015 Can you give me more information as to how this is possible in conjunction to the website posted? Thanks
computergroove Posted September 7, 2015 Posted September 7, 2015 I am assuming you mean the website I posted above. Goto the website and it will show you what region you are connecting from. You can use autoit to read that location and compare it to "Korea" or something similar. If it changes then reset your proxy settings. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
aa2zz6 Posted September 8, 2015 Author Posted September 8, 2015 (edited) I could implement something to read and detect the IP via web. I was wondering whether there is a way to move away from image searches in general. What if I got the class and Instance and used a read to search whether the VPN was activated. Edited September 9, 2015 by aa2zz6 Included more information. Sorry
aa2zz6 Posted September 9, 2015 Author Posted September 9, 2015 (edited) So I did some research and built the following code but I don't think it's quite right. The program has two CLASS:SysListView32 but each has a different Instance( 1 ) and ( 2 ). I was hoping it would automatically read the first Class[...] Instance[1] since it's the top section of the application but it doesn't return the Read [VPN Gate Connection]. I'll post a picture below to better show it.Func test() If ProcessExists($var) Then MsgBox($MB_SYSTEMMODAL, "SoftEther VPN", "VPN is running", 2) Sleep(500) WinSetState("SoftEther VPN Client Manager", "", @SW_RESTORE) Sleep(500) For $i = 1 To 3 $string &= "Line " & $i & @CRLF Next ControlSetText("[CLASS:SysListView32[1]]", "", "Edit1", $string) Sleep(1000) $text = WinGetText("[ACTIVE]", "") MsgBox(0, "Text read was:", $text) Else $chrome = ShellExecute("C:\Users\Public\Desktop\SoftEther VPN Client Manager.lnk") ProcessWait($var) Sleep(500) WinSetState("[active]", "", @SW_SHOWMINIMIZED) EndIf EndFunc ;==>test Edited September 9, 2015 by aa2zz6 Personal information on the picture
computergroove Posted September 11, 2015 Posted September 11, 2015 (edited) When you are connected to your vpn your wan ip will show from Korea.#include <Inet.au3> #include <MsgBoxConstants.au3> Local $oIE = _INetGetSource("http://wanip.info/") Local $CharacterCount = StringInStr($oIE,'.png" alt="');return the number of characters that '.png" alt="' starts at in the html source Local $TrimmedHTML = StringTrimLeft($oIE,$CharacterCount + 10);trim the characters from the left of country Local $sCountry = StringLeft($TrimmedHTML,5);Read the characters from the country alt code in the HTML. Korea has 5 letters MsgBox(0,0,$sCountry)Use this to get your current wan ip detected location and use it to compare to what you want. If it says Korea then sleep 30 minutes. If it doesn't say Korea then reinitialize your vpn. For my the above returns 'us" /' because Im in the us with a us wan ip. Edited September 11, 2015 by computergroove aa2zz6 1 Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now