ipsec example block ports

        'https://stackoverflow.com/questions/27396742/how-to-block-all-but-a-specific-list-of-ip-addresses-on-a-given-port-using-ipsec


        CreateCommandAndRunIt("ipsec static add filterlist name=filterlist_RDPGuardRichStyle", "filterlist")

        'CreateCommandAndRunIt("ipsec static delete filter filterlist=filterlist_RDPGuardRichStyle srcaddr=192.168.2.3 dstaddr=Me protocol=tcp srcport=0 dstport=1234", "filter")

        CreateCommandAndRunIt("ipsec static add filter filterlist=filterlist_RDPGuardRichStyle srcaddr=192.168.2.3 dstaddr=Me protocol=tcp srcport=0 dstport=1234", "filter")

        CreateCommandAndRunIt("ipsec static add filteraction name=action_RDPGuardRichStyle action=block", "block")

        CreateCommandAndRunIt("ipsec static add policy name=policy_RDPGuardRichStyle assign=yes", "assign")

        CreateCommandAndRunIt("ipsec static add rule name=rule_RDPGuardRichStyle policy=policy_RDPGuardRichStyle filterlist=filterlist_RDPGuardRichStyle filteraction=action_RDPGuardRichStyle", "rule")

        ''CreateCommandAndRunIt("ipsec static add filterlist name=filterlist_RDPGuardRichStyle", "filterlist")

        'CreateCommandAndRunIt("ipsec static delete filter filterlist=filterlist_RDPGuardRichStyle srcaddr=10.222.222.223 dstaddr=Me protocol=tcp srcport=0 dstport=1234", "filter")

        CreateCommandAndRunIt("ipsec static add filter filterlist=filterlist_RDPGuardRichStyle srcaddr=10.222.222.223 dstaddr=Me protocol=tcp srcport=0 dstport=1234", "filter")

        '' CreateCommandAndRunIt("ipsec static delete filter filterlist=filterlist_RDPGuardRichStyle srcaddr=10.222.222.222 dstaddr=Me protocol=tcp srcport=0 dstport=1234", "filter")

        CreateCommandAndRunIt("ipsec static add filter filterlist=filterlist_RDPGuardRichStyle srcaddr=10.222.222.222 dstaddr=Me protocol=tcp srcport=0 dstport=1234", "filter")


    Function CreateCommandAndRunIt(sArgs As String, sTag As String) As String

        Dim oProc As New Process

        oProc.StartInfo.FileName = "C:\Windows\System32\netsh.exe"

        oProc.StartInfo.Arguments = sArgs

        oProc.StartInfo.RedirectStandardError = True

        oProc.StartInfo.RedirectStandardOutput = True

        oProc.StartInfo.UseShellExecute = False

        Try

            Dim blnOk As Boolean = oProc.Start()

            If blnOk Then

                WriteFile("Success: " & Now & " " & sTag, "c:\temp\servicefailed.txt")

                Return oProc.StandardOutput.ReadToEnd.ToString

            Else

                WriteFile("Failed: " & Now & " " & " " & sTag & " ", "c:\temp\servicefailed.txt")

                Return oProc.StandardError.ReadToEnd.ToString

            End If

        Catch ex As Exception

            WriteFile("Failed: " & Now & " " & " " & sTag & " " & ex.Message.ToString, "c:\temp\servicefailed.txt")

            Return oProc.StandardError.ReadToEnd.ToString

            'Me.Stop()

        End Try

    End Function

x