Пример #1
0
        private void Portblocker()
        {
            string ipadress = GetLocalIPAddress();

            apparaat    = new Apparaat(GetMacAddress(ipadress));
            apparaat    = database.GetBlockedPort(apparaat.macadres);
            porttoblock = apparaat.blockedport;
            block       = apparaat.block;
            macadres    = apparaat.macadres;
            string stdout, stderr;

            if (block == 0)
            {
                RunShellCommand(
                    "netsh.exe",
                    String.Format("advfirewall firewall delete rule name=\"{0}\" dir=out protocol={1} remoteport={2}",
                                  "Block Port 80",
                                  "TCP",
                                  porttoblock),
                    out stdout,
                    out stderr);
                database.DeleteRow(apparaat.macadres);
            }
            else
            {
                RunShellCommand(
                    "netsh.exe",
                    String.Format("advfirewall firewall add rule name=\"{0}\" dir=out action=block protocol={1} remoteport={2}",
                                  "Block Port 80",
                                  "TCP",
                                  porttoblock),
                    out stdout,
                    out stderr);
            }
        }
Пример #2
0
        public Apparaat GetBlockedPort(string macadres)
        {
            int blockedport = 0;
            int block       = 0;

            try
            {
                using (OracleConnection connection = new OracleConnection(connString))
                {
                    connection.Open();
                    OracleCommand cmd = new OracleCommand("SELECT PORT, BLOCK from APPARAAT WHERE MAC = '" + macadres + "'", connection);
                    using (OracleDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            blockedport = Convert.ToInt32(reader["PORT"]);
                            block       = Convert.ToInt32(reader["BLOCK"]);
                        }
                    }
                }
                return(apparaat = new Apparaat(blockedport, block, macadres));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }