antfuentes87 Posted March 7, 2013 Share Posted March 7, 2013 (edited) 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. expandcollapse popupFunc 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 March 7, 2013 by antfuentes87 Link to comment Share on other sites More sharing options...
computergroove Posted March 7, 2013 Share Posted March 7, 2013 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 Link to comment Share on other sites More sharing options...
antfuentes87 Posted March 7, 2013 Author Share Posted March 7, 2013 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? Link to comment Share on other sites More sharing options...
antfuentes87 Posted March 7, 2013 Author Share Posted March 7, 2013 Anybody? Still can not get netsh to work with changing the IP on a VPN connection. Just looking for a little direction, please. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted March 7, 2013 Moderators Share Posted March 7, 2013 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 More sharing options...
antfuentes87 Posted March 7, 2013 Author Share Posted March 7, 2013 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 More sharing options...
jchd Posted March 7, 2013 Share Posted March 7, 2013 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Moderators JLogan3o13 Posted March 8, 2013 Moderators Share Posted March 8, 2013 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 More sharing options...
antfuentes87 Posted March 8, 2013 Author Share Posted March 8, 2013 All good, I finally figured it out. Thanks guys. Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted June 3, 2013 Share Posted June 3, 2013 rasdial connectionname /disconnect disconnect the connection Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
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