Jump to content
Sign in to follow this  
antfuentes87

Connecting to VPN?

Recommended Posts

antfuentes87

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

Share this post


Link to post
Share on other sites
computergroove

http://en.kioskea.net/forum/affich-13513-how-to-change-ip-address-from-command-prompt


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

Share this post


Link to post
Share on other sites
antfuentes87

So I am guessing this mean I can change it with netsh? Cause I tried netsh int set ip address "VPN" static 12.324.12.124 and did not work. Do you have a example on how to write the command correctly for VPN?

Share this post


Link to post
Share on other sites
antfuentes87

Anybody? Still can not get netsh to work with changing the IP on a VPN connection. Just looking for a little direction, please.

Share this post


Link to post
Share on other sites
JLogan3o13

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.


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
antfuentes87

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.

Share this post


Link to post
Share on other sites
jchd

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)

Share this post


Link to post
Share on other sites
antfuentes87

All good, I finally figured it out. Thanks guys.

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

rasdial connectionname /disconnect

disconnect the connection


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×