begin process at 2010 02 10 00:52:25
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Réseaux & Internet

 > CONFIGURATION XP FIREWALL

CONFIGURATION XP FIREWALL


 Information sur la source

 Description

Classe permettant d'ajouter, activer/désactiver une règle de configuration du FireWall d'XP

Source

  • public class XPFireWall
  • {
  • /// <summary>
  • /// Configuration du firewall windows
  • /// </summary>
  • /// <param name="protocol">Protocol de communication du port</param>
  • /// <param name="port">Numero du port</param>
  • /// <param name="mode">Mode de configuration</param>
  • /// <param name="scope">Etendue</param>
  • /// <param name="RuleName">Nom de la règle de configuration</param>
  • /// <returns>Execution reussit</returns>
  • public bool SetPort(Protocol protocol, int port, Mode mode, Scope scope, string RuleName)
  • {
  • bool _blnReussit = false;
  • //Version de L'OS Minimum pour la configuration du firewall
  • Version _versOSVersion = new Version(5, 1, 2600);
  • if ((Environment.OSVersion.Version > _versOSVersion) || ((Environment.OSVersion.Version == _versOSVersion) && (int.Parse(Environment.OSVersion.ServicePack.Replace("Service Pack ", "")) >= 2)))
  • {
  • //Concaténation des parametres
  • string _strParam = string.Concat(new object[] { "firewall set portopening ", protocol, " ", port, " ", RuleName, " ", mode, " ", scope });
  • //Parametrage du process NETSH
  • Process _procNetSH = new Process();
  • _procNetSH.StartInfo.FileName = "netsh";
  • _procNetSH.StartInfo.Arguments = _strParam;
  • _procNetSH.StartInfo.CreateNoWindow = true;
  • _procNetSH.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  • _procNetSH.StartInfo.UseShellExecute = false;
  • _procNetSH.StartInfo.RedirectStandardOutput = true;
  • _procNetSH.StartInfo.RedirectStandardError = true;
  • try
  • {
  • //Execution du processus NETSH
  • _procNetSH.Start();
  • _procNetSH.WaitForExit(20000);
  • if (_procNetSH.ExitCode == 0)
  • {
  • _blnReussit = true;
  • }
  • }
  • catch
  • {
  • }
  • finally
  • {
  • if (_procNetSH != null)
  • {
  • _procNetSH.Close();
  • _procNetSH.Dispose();
  • }
  • }
  • }
  • return _blnReussit;
  • }
  • public enum Mode
  • {
  • Enable,
  • Disable
  • }
  • public enum Profil
  • {
  • Current,
  • Domain,
  • Standard,
  • All
  • }
  • public enum Protocol
  • {
  • TCP,
  • UDP,
  • ALL
  • }
  • public enum Scope
  • {
  • All,
  • Subnet,
  • Custom
  • }
  • }
    public class XPFireWall
    {
        /// <summary>
        /// Configuration du firewall windows
        /// </summary>
        /// <param name="protocol">Protocol de communication du port</param>
        /// <param name="port">Numero du port</param>
        /// <param name="mode">Mode de configuration</param>
        /// <param name="scope">Etendue</param>
        /// <param name="RuleName">Nom de la règle de configuration</param>
        /// <returns>Execution reussit</returns>
        public bool SetPort(Protocol protocol, int port, Mode mode, Scope scope, string RuleName)
        {
            bool _blnReussit = false;
            
            //Version de L'OS Minimum pour la configuration du firewall
            Version _versOSVersion = new Version(5, 1, 2600);

            if ((Environment.OSVersion.Version > _versOSVersion) || ((Environment.OSVersion.Version == _versOSVersion) && (int.Parse(Environment.OSVersion.ServicePack.Replace("Service Pack ", "")) >= 2)))
            {
                //Concaténation des parametres
                string _strParam = string.Concat(new object[] { "firewall set portopening ", protocol, " ", port, " ", RuleName, " ", mode, " ", scope });

                //Parametrage du process NETSH
                Process _procNetSH = new Process();
                _procNetSH.StartInfo.FileName = "netsh";
                _procNetSH.StartInfo.Arguments = _strParam;
                _procNetSH.StartInfo.CreateNoWindow = true;
                _procNetSH.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                _procNetSH.StartInfo.UseShellExecute = false;
                _procNetSH.StartInfo.RedirectStandardOutput = true;
                _procNetSH.StartInfo.RedirectStandardError = true;
                try
                {
                    //Execution du processus NETSH
                    _procNetSH.Start();
                    _procNetSH.WaitForExit(20000);
                    if (_procNetSH.ExitCode == 0)
                    {
                        _blnReussit = true;
                    }
                }
                catch
                {
                }
                finally
                {
                    if (_procNetSH != null)
                    {
                        _procNetSH.Close();
                        _procNetSH.Dispose();
                    }
                }
            }
            return _blnReussit;
        }

        public enum Mode
        {
            Enable,
            Disable
        }
        public enum Profil
        {
            Current,
            Domain,
            Standard,
            All
        }
        public enum Protocol
        {
            TCP,
            UDP,
            ALL
        }
        public enum Scope
        {
            All,
            Subnet,
            Custom
        }
   }



 Sources du même auteur

Source avec Zip Source .NET (Dotnet) GENERIC DAL
Source .NET (Dotnet) LANCER LES OPTIONS D'IMPRESSION D'UNE IMPRIMANTE
Source avec Zip Source avec une capture Source .NET (Dotnet) SQL2005SCRIPTEXTRACTOR (POUR SUBVERSION(SVN))
Source avec Zip Source .NET (Dotnet) JOUER AVEC VOS SHORTCUTS (AJOUT, SUPPRESSION, MODIFICATIONS)

 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) HTTP FLOOD STRESS TEST par NightMareLmW
Source avec Zip Source avec une capture Source .NET (Dotnet) SERVEUR/ESCLAVE MODBUS TCP/IP par SteveFuchsIT
Source avec Zip Source avec une capture Source .NET (Dotnet) IPHELPER - PORTS TCP/UDP, TABLES DE ROUTAGE/ARP + FONCTIONS ... par Willi
Source avec Zip Source avec une capture Source .NET (Dotnet) [.NET3.5] SYSTEM.IO.PIPES - UTILISATION D'UN CANAL NOMMÉ par Willi
Source avec Zip Source .NET (Dotnet) MESSAGES PERSOS MSN par XelectroX

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture Source .NET (Dotnet) MINIFIREWALL+CAPTUREUR par pch_hotline
Source avec Zip Source avec une capture Source .NET (Dotnet) [.NET2] DÉMONSTRATION SUR L'UTILISATION DE L'API DU FIREWALL... par Willi
Source avec Zip Source avec une capture Source .NET (Dotnet) CLASSE PERMETTANT DE MODIFIER LES PARAMÈTRES DU FIREWALL DE ... par LUDINSKI

Commentaires et avis

Commentaire de developper_man le 15/02/2006 12:08:09

bonjour,
j'ai vraiment aimé votre code,
mais quand je veut l'executé j'ai une erreur : tout simplement parce que ServicePack n'existe pas dans Environment.OSVersion !!! merci de me tenir au courant
a+

Commentaire de zebobo5 le 15/02/2006 13:52:21

Salut,
"ServicePack" n'existe pas... tu dois être avec le famework 1.1.
Je peux pas te dire comment corriger ce problème, mais si quelqu'un utilise encore le framework 1.1 (lol) et qui a une alternative, je suis prenneur.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Scanner les ports à la manière d'un firewall [ par Siteauludo ] Bonjour,J'aimerai faire une petite application qui me scanne le ports et qui m'inscrive dans un log toutes les informations qui y passent.Cela fonctio Programmation Firewall [ par CHABRY ] Bonjour,Je suis un étudiant en Master 2: Ingénierie des Réseaux, Communications Mobiles et Sécurité à Valenciennes.J'ai un projet à faire qui consiste


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,811 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales