|
Post by DaFaKing on Jan 7, 2017 3:12:26 GMT -5
Making a VPN Kill switch for lazy windows people. Rough draft. Press Start button type Task Scheduler and run it Click Action on the menubar and select “Create Task" Type in a name for this new task. Tick checkbox for “Run with highest privileges“ Select Trigger tab and click the New button Click drop down menu for Begin the Task and Select “On an event" Select RasClient for Source Enter the Event ID as 20226 then click OK Go to the Actions tab and click the New button Ensure the action is “Start a program“ At the program/script input box, enter powershell.exe In the arguments box, enter "Get-NetAdapter | Disable-NetAdapter -Confirm:$false" This should disable all network connections when the VPN connection is lost BTW...I still need to proof read this. ---------------------------- This should kill all connections when VPN is dropped. Working on re-enable. Thinking it should be a simple batch file. Continued.... Batch file with "netsh interface set interface name="Ethernet" admin=enabled" ------------------- BTW...the kill switch and restore works perfectly here. Almost ready for people to try out if they want to. I will create a tutorial. Still want to tweak some things.
|
|
|
Post by DaFaKing on Jan 7, 2017 17:39:12 GMT -5
Press Start button type Task Scheduler and run it Click Action on the menubar and select “Create Task" Type in a name for this new task. Tick checkbox for “Run with highest privileges“ Select Trigger tab and click the New button Click drop down menu for Begin the Task and Select “On an event" Select RasClient for Source Enter the Event ID as 20226 then click OK Go to the Actions tab and click the New button Ensure the action is “Start a program“ At the program/script input box, enter "powershell" Add argument -windowstyle hidden "& ""C:\PS.ps1"""Go to your network connections to get the name of your Network Adapter. This is the Adapter that use to connect to your ISP "normally". Replace "ethernet" with the name of your adapter in the code below. Copy and past this into a text document and save the file as "PS.ps1". You are changing the extension of the the text file..so windows will probably complain... just select OK. Put this new file in your C:\ directory.... so it will be C:\PS.ps1 Get-NetAdapter | Disable-NetAdapter -Confirm:$false
Function Show-MessageBox{
Param( [Parameter(Mandatory=$True)][Alias('M')][String]$Msg, [Parameter(Mandatory=$False)][Alias('T')][String]$Title = "", [Parameter(Mandatory=$False)][Alias('OC')][Switch]$OkCancel, [Parameter(Mandatory=$False)][Alias('OCI')][Switch]$AbortRetryIgnore, [Parameter(Mandatory=$False)][Alias('YNC')][Switch]$YesNoCancel, [Parameter(Mandatory=$False)][Alias('YN')][Switch]$YesNo, [Parameter(Mandatory=$False)][Alias('RC')][Switch]$RetryCancel, [Parameter(Mandatory=$False)][Alias('C')][Switch]$Critical, [Parameter(Mandatory=$False)][Alias('Q')][Switch]$Question, [Parameter(Mandatory=$False)][Alias('W')][Switch]$Warning, [Parameter(Mandatory=$False)][Alias('I')][Switch]$Informational, [Parameter(Mandatory=$False)][Alias('TM')][Switch]$TopMost)
#Set Message Box Style IF($OkCancel){$Type = 1} Elseif($AbortRetryIgnore){$Type = 2} Elseif($YesNoCancel){$Type = 3} Elseif($YesNo){$Type = 4} Elseif($RetryCancel){$Type = 5} Else{$Type = 0} #Set Message box Icon If($Critical){$Icon = 16} ElseIf($Question){$Icon = 32} Elseif($Warning){$Icon = 48} Elseif($Informational){$Icon = 64} Else { $Icon = 0 } #Loads the WinForm Assembly, Out-Null hides the message while loading. [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null If ($TopMost) { #Creates a Form to use as a parent $FrmMain = New-Object 'System.Windows.Forms.Form' $FrmMain.TopMost = $true #Display the message with input $Answer = [System.Windows.Forms.MessageBox]::Show($FrmMain, $MSG, $TITLE, $Type, $Icon) #Dispose of parent form $FrmMain.Close() $FrmMain.Dispose() } Else { #Display the message with input $Answer = [System.Windows.Forms.MessageBox]::Show($MSG , $TITLE, $Type, $Icon) } #Return Answer Return $Answer }
Show-MessageBox -Critical -Msg "VPN CONNECTION LOST - PRESS OK TO RESTORE ISP CONNECTION" -TopMost
Enable-NetAdapter -Name ethernet -Confirm:$false
Exit
Go back to task scheduler and right click on your newly created task, then select run from the drop down menu. You should then be disconnected from the network. Press OK to restore your ISP connection. I've only tested this locally. Test for yourself. Let me know if something in this tutorial does not make sense or if I have made a mistake. I will be editing this later. There is a way to use a VB Script to avoid having the powershell console window flash up when this is ran. I have also made this into an executable locally which makes setup easier. That said, I need to think of a way to make that work for network adapters with varying names. Perhaps users will just need to change the name of their adapter. We'll see if there is any interest in this and add to it later. Stay Safe and Secure. NOTE: If for some reason the connection to your ISP is not restored after clicking OK.... you can just manually re-enable your adapter by right clicking on it and selecting "enable" from the drop down menu in Network Connections. Use at your own risk. I accept no responsibility if you screw things up
|
|