matzas
(Fresh Scripter)
2014-03-03 09:29 AM
Help with Network Switch Script.

hi all,

We have several laptops, I need to make sure none of them will connect to the Local Network and to other network (WiFi, Netstick, Modem, Etc) at the same time.

I thought of a script that:

-will check the status of each network card. (for not enable a disabled card)
-will check if the physical (LAN) card is connected.
if LAN is connected and some other network cards are connected it will disable the other card.
if LAN is disconnected it will enable back the other network card (not the ones that were disabled before the script).

the script will run in hide console, in the background, and will do it's checks every 2 seconds.

i thought to use GetCurrentSSID() and GetIPOptions() but i don't know how to disable or enable the network card.

thanks in advance,

Amir.


LonkeroAdministrator
(KiX Master Guru)
2014-03-03 03:39 PM
Re: Help with Network Switch Script.

have you considered enabling this feature in bios?

Mart
(KiX Supporter)
2014-03-03 04:04 PM
Re: Help with Network Switch Script.

This works for me.
I stuffed it in a function because you may be busing it a few times and then a function may save some code lines and make it more readable.

 Code:
Break on

$connection = "Connection name goes here"
$state = "state goes here (Enabled or Disabled)"

SetConnectionState($connection, $state)


Function SetConnectionState($connection, $state)
	If Trim($connection) = ""
		Exit 87
	EndIf
	If $state <> "Enabled" And $state <> "Disabled"
		Exit 87
	EndIf

	$shellcommand = 'NetSH interface set interface "' + $connection + '" ' + $state
	Shell $shellcommand
	
	Exit @ERROR
EndFunction