Solved

How to schedule automatic enable/disable of LAN connections

Posted on 2010-08-29
17
937 Views
Last Modified: 2013-11-25
I have two internet connection attached with two different lan cards. Lan1 and Lan2

I want to automatically enable Lan1 From 10 AM to 6 PM and then disable Lan1 and enable Lan2 from 6PM to 10 AM.

How can I do that?
0
Comment
Question by:pawan-agr
17 Comments
 
LVL 3

Assisted Solution

by:Andre Thibodeau
Andre Thibodeau earned 250 total points
ID: 33552854
Use netsh

Write a batch script, then use your task scheduler to run it.

ie:

netsh int set interface name="Local Area Connection" admin=disabled
netsh int set interface name="Local Area Connection" admin=enabled

Note: Admin permissions needed for netsh

Andre
0
 

Author Comment

by:pawan-agr
ID: 33552939
athibodeau:

I ran the command but I received the error.

Here is the screenshot:
http://screencast.com/t/OThmMzI1NG
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 33552949
interface name should be replaced by NICs name (you probably changed your default name or they have order numbers i.e. Local Area Network 1)

prepare 2 bat or cmd files, one:
netsh int set interface name="LAN1" admin=disabled
netsh int set interface name="LAN2" admin=enabled

second:
netsh int set interface name="LAN1" admin=enabled
netsh int set interface name="LAN2" admin=disabled

where LAN1 and LAN2 are your connections. Run ipconfig /all in command-line and check what names they have.

and set a scheduled tasks on that PC/server on administrative rights.
0
 
LVL 3

Expert Comment

by:Andre Thibodeau
ID: 33552974
use "netsh interface ip show config" to quickly show you the interface config.

0
 

Author Comment

by:pawan-agr
ID: 33553131
I have renamed my NICs name to "NTC". So, it's not the wrong name problem.

If I use any other arbitary name instead of NTC then I get this error.
"An interface with this name is not registered with the router."

So, I'm 100% sure that, it's not the wrong name problem.

I'm still getting the same error as I shown in the screenshot above.

(I'm using windows xp and logged in with the administrator account)
0
 
LVL 3

Expert Comment

by:Andre Thibodeau
ID: 33553161
netsh needs administrative permissions

Open your cmd prompt as an administrator  "run as administrator", then run your script.

once you get script running, you can tell task scheduler to run as admin.

Andre
0
 
LVL 3

Expert Comment

by:Andre Thibodeau
ID: 33553182
here is one of my scripts for my dell 1390 wireless adapter,  c:\bin\dell1390.cmd

netsh interface ipv4 set address "Dell 1390" admin=enable
netsh interface ipv4 set address "Dell 1390" static 192.168.3.201 255.255.255.0 192.168.3.1 1
netsh interface ipv4 set dns name="Dell 1390" source=static addr=192.168.3.1
netsh interface ipv4 add dnsservers "Dell 1390" 8.8.8.8 index=2

I then created a shortcut to the script.  In the shortcut properties you can go in to advanced and runas administrator.

Andre
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 3

Expert Comment

by:Andre Thibodeau
ID: 33553265
sorry typo in last message.  should read as.  (copy and paste error)

netsh interface set interface name="Dell 1390" admin=enable
netsh interface ipv4 set address "Dell 1390" static 192.168.3.201 255.255.255.0 192.168.3.1 1
netsh interface ipv4 set dns name="Dell 1390" source=static addr=192.168.3.1
netsh interface ipv4 add dnsservers "Dell 1390" 8.8.8.8 index=2
0
 

Author Comment

by:pawan-agr
ID: 33559422
athibodeau:

I'm still getting the exact same error even running the cmd as administrator.

Does this command work properly in windows XP?

This forum post says:
http://www.compatdb.org/forums/topic/26746-disabling-and-enabling-network-connections-using-cli/
(for others interested, the command works fine with Windows Server 2003, and the version of netsh in XP may not support disabling in this fashion yet).
0
 
LVL 3

Expert Comment

by:Andre Thibodeau
ID: 33561479
good question.  I tried the command on my XP box and got same results as you, but other OS's like Windows 2003, 2008, 7, work fine.

I would venture to guess the admin=disabled/enabled is not supported with Windows XP.  Even though it is listed.  I see lots of posts with people having a similar issue with XP.

So...  Looks like netsh is not for you.

Take a look at using devcon, with devcon you can enable and disable devices directly to the device manager.  I have never tried this with a network adapter, but it should work.

http://support.microsoft.com/kb/311272

First query the devices and look for the HardwareID
devcon hwids =net

once you have the HardwareID of the adapter.
devcon disable HardwardID

Andre

0
 
LVL 3

Expert Comment

by:Andre Thibodeau
ID: 33561879
Here is another idea.

I would imagine you want to change your default gateway at certain time of day.

Instead of disabling and enabling the adapters, try changing the default gateway using netsh.

something like...
netsh interface ip set address "Local Area Connection 1" static 192.168.1.100 255.255.255.0
netsh interface ip set address "Local Area Connection 2" static 192.168.2.100 255.255.255.0 192.168.2.1 1  (note the gateway 192.168.2.1)

then the reverse to switch gateways
netsh interface ip set address "Local Area Connection 1" static 192.168.1.100 255.255.255.0 192.168.1.1 1
netsh interface ip set address "Local Area Connection 2" static 192.168.2.100 255.255.255.0

Andre
0
 

Author Comment

by:pawan-agr
ID: 33567334
athibodeau:

Can you please test the DevCon tool and give me a simple guide to follow?
0
 

Author Comment

by:pawan-agr
ID: 33567349
Changing the default gateway is a nice idea but it will create confusion as I won't precisely know from which connection the internet is coming from. I think it will be great to use DevCon instead.
0
 
LVL 44

Accepted Solution

by:
Darr247 earned 250 total points
ID: 33607397
No matter what you rename the adapters in Network Connections, that doesn't change the interface name[s], which you can see at the top of the "route print" output (unless they are disabled).

But to start on the devcon method, you need to know the hardware instance IDs of the NICs.
To find the hardware IDs, run

C:\path\where\you\unzipped\devcon\i386_or_ia64\> devcon hwids PCI\VEN*

in a Command Prompt window, then scroll back up and look for "ethernet" or "network" in the name (the "name" will match what it says in 'route print' but devcon needs the hardware instance ID).

If there are too many devices or not enough buffer space in the command window, preventing you from scrolling back far enough to find the NICs' device IDs, you can run

... \> devcon hwids PCI\VEN* > C:\PCI-HWIDS.TXT

then open C:\PCI-HWIDS.TXT in notepad.

It should list 4 to 8 IDs for each device, in varying granularities of uniqueness. To make it work with cards from the same vendor, you'll probably have to go to at least the subsys level to get them unique between the cards.

e.g.
... \> devcon disable "PCI\VEN_xxxx&DEV_xxxx&SUBSYS_xxxxxxxx"

... \> devcon enable "PCI\VEN_xxxx&DEV_xxxx&SUBSYS_xxxxxxxx"

you MUST enclose the IDs in double quotes or it won't look past the PCI\VEN_xxxx part, which if they're both from the same vendor are probably identical between the 2 NICs.
0
 

Author Closing Comment

by:pawan-agr
ID: 33611819
Thank you athibodeau and Darr247. You both have helped me a lot with this.

I have splitted the points in both of you.

athibodeau, you put in lots of efforts here but unfortunately your solution didn't work in windows xp. I appreciate all your help.

Darr247: Your solution worked beautifully and I'm ready to implement it. :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Trying to figure out group policy inheritance and which settings apply where can be a chore.  Here's a very simple summary I've written which might help.  Keep in mind, this is just a high-level conceptual overview where I try to avoid getting bogge…
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now