Jump to content

Connecting to VPN?


Recommended Posts

I tried making a function that would disconnect from a VPN, switch the IP, and reconnect. It does work, but not optmial. I tried looking for a DOS command, but only found rasdial whcih lets you connect to a VPN (but does not allow you to switch the IP) and disconnect from a VPN. Wondering if anyone has a better way for doing this, cause this is all I could come up with.

Func changeVPN_IP()
$ipLineCount = _FileCountLines("ip.txt")
$ip = FileReadLine("ip.txt", round(random(1, $ipLineCount)))
$rasphoneTitle = 'Network Connections - rasphone.pbk'
$vpnTitle = 'VPN Properties'

;CLOSE ALL RASPHONE AND IEXPLORE
M_closeProcess("rasphone.exe")
M_closeProcess("iexplore.exe")
M_closeProcess("netsh.exe")
M_closeProcess("mqsvc.exe")

;CLOSE WINDOWS
M_winKill("Remote Access Phonebook")
M_winKill("Windows host process (Rundll32)")
M_winKill("Error Connecting to VPN")
M_winKill("Error Connecting")

;DISCONNECT FROM VPN
_RunDos('rasdial "VPN" /disconnect')
Sleep(1500)

;START RASPHONE WHICH WILL ALLOW TO CHANGE PROPS OF THE VPN
_RunDos("start rasphone.pbk")

;HIDE RASPHONE
M_hideWindow($rasphoneTitle)

;CLICK PROPS ON RASPHONE
ControlClick($rasphoneTitle, "", 1460, "left", 1)

;HIDE VPN PROPS
M_hideWindow($vpnTitle)

;SEND IP TO VPN PROPS
ControlSend("", "", 1427, $ip)

;CLICK OK ON VPN PROPS
ControlClick ($vpnTitle, "", 1, "left", 1)

;HIDE RASPHONE
M_hideWindow($rasphoneTitle)

;CLICK CANCEL ON RASPHONE
ControlClick ($rasphoneTitle, "", 1455, "left", 1)

;DISABLE LAN **HAVE TO DO THIS IN ORDER FOR THE VPN TO RECONNECT
_RunDos('netsh interface set interface "Local Area Connection" DISABLED')
Sleep(1500)

;ENABLE LAN SO WE CAN ENABLE VPN
_RunDos('netsh interface set interface "Local Area Connection" ENABLE')
Sleep(5000)

;CONNECT TO VPN WITH NEW IP
sendto_DOS('rasdial "VPN" antfuentes1252 F1wqQVU8')
Sleep(6000)
EndFunc

Func M_hideWindow($windowName)
Do
Sleep(100)
Until WinExists($windowName, "") = 1
WinSetState ($windowName, "", @SW_HIDE)
EndFunc

Func M_closeProcess($processName)
Do
ProcessClose($processName)
Sleep(100)
Until ProcessExists($processName) = 0
Sleep(100)
EndFunc

Func M_winKill($windowName)
Do
WinKill($windowName, "")
Sleep(100)
Until WinExists($windowName) = 0
Sleep(100)
EndFunc
Edited by antfuentes87
Link to comment
Share on other sites

  • Moderators

I guess my first question is why do you need to change the IP and then reconnect? There may be a simpler way to accomplish what you're trying to do.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I guess my first question is why do you need to change the IP and then reconnect? There may be a simpler way to accomplish what you're trying to do.

I have to use a VPN, no getting around that. I need to disonnect from the VPN, change the address, and reconnect. I would like to use this across many differenet scripts, so there is no finding another way, cause each situation is different. So I need a function that can stand on its own and be able to use that function in my other scripts. What I have for now, does work, just thought it be fast if I could do it all through DOS or something along those lines.

Link to comment
Share on other sites

We don't ask you to stop using a VPN. We merely ask why you need to change address in the middle of a VPN session in that many different use contexts.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

As jhcd stated, I wonder why you would need to do this, unless you're trying to avoid/bypass something?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 2 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...