|
Answer» Hi All,
I often have to dive into my Local Area Network Connection at work and change the default gateway, so I can VNC into a client's site. The path is Properties/ Internet Protocol(TCP/IP) Properties/General tab, Default Gateway field. Once I'm finished at the client's site I have to change the default gateway back so my internet works. I have tried adding two gateways under the advance tab, but it does not work.
Well, I'm GETTING lazy in my OLD age and would like to create a BATCH file that changes my default gateway without changing the IP Address or SUBNET Mask. My idea is to have one batch file that changes it back and forward. I will copy and delete 'On' and 'Off' batch file shortcuts to my desktop, depending on the status of the default gateway.
Cheers,
GavThis may help you flip-flop the values:
Code: [Select]On Error Resume Next
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems Select Case objItem.DefaultIPGateway Case "xxx.xxx.xxx.xxx" arrGateways = Array("yyy.yyy.yyy.yyy") objItem.SetGateways(arrGateways) Case "yyy.yyy.yyy.yyy" arrGateways = Array("xxx.xxx.xxx.xxx") objItem.SetGateways(arrGateways) End Select Next
Change the x and y masks to something valid. Save the script with a vbs extension and run from the run box or the command line as wscript scriptname.vbs.
Good luck. 8-)If you want to do it with a batch file, you can USE the following line: Code: [Select]netsh interface ip set address name="Local Area Connection" gateway=192.168.1.1 gwmetric=0The "Local Area Connection" needs to be the name of your network adapter (if different). Just replace the 192.168.1.1 with your actual gateway address for normal and call it On.bat, and then replace it again for your VNC gateway address and call it Off.bat.Thanks again
|