Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write a batch file to toggle my network adapters?

At my work, there is a company intranet I can connect to, as well as a Wifi network. But, it is company policy that we cannot connect to both networks simultaneously on one machine.

I need to use either network at different times though, and the only way I've been able to do so is by going to "Change Adapter Settings" somewhere in the Network section of Control Panel, then disabling whichever adapter I'm using (either local area network or wifi) and enabling the other one.

As a programmer the repetitiveness and tediousness of this task bothers me, so is there a script I could write to toggle these?

like image 689
Austin R Avatar asked Dec 28 '12 15:12

Austin R


1 Answers

You should look into netsh:

ex: netsh interface set interface "Local Area Connection" DISABLED

(or ENABLED)

create 2 scripts that do an ENABLED on the one you want and DISABLED on the other, and vice versa (or 1 script that first sees which one is up and which is down, and inverts)

This command can also list the state of the interfaces.

But it behaves differently (or uses a different syntax) between several flavors of windows... so you can also have a look at MicroSoft' devcon. Or another possibility: wmic.

like image 74
Olivier Dulac Avatar answered Oct 13 '22 18:10

Olivier Dulac