Example #1
0
        void DisconnectViaTcpMessage()
        {
            int DisableButtonIntervalMs = 4000;

            HsState state = UpdateHsState();

            isForceDisconnected = true;

            foreach (var c in state.Connections)
            {
                if (!Util.IsRemoteConnection(c))
                {
                    continue;
                }

                Console.WriteLine("Closing connection. {0}", c);
                String error = iphlpapi.CloseRemoteIP(c.ToTcpRow());
                if (null != error)
                {
                    MessageBox.Show(String.Format("Cannot close connection {0}\r\nError: {1}", c, error));
                }
            }

            System.Threading.Thread.Sleep(DisableButtonIntervalMs);
            isForceDisconnected = false;
        }
Example #2
0
        public HsState UpdateHsState()
        {
            Process[] processes = ListHsProcesses();
            List <iphlpapi.MIB_TCPROW_OWNER_PID> connections = ListHsConnections(processes);
            var state = new HsState(processes, connections);

            if (state.IsRunning && firewall == null)
            {
                firewall = Firewall.TryCreate(state.BinaryPath);
            }

            return(state);
        }