网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > C# > 正文
自己开发程序管理WINDOWS防火墙
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/14
下载{$ArticleTitle}原创论文样式
最近项目中需要通过程序自动设置windows 防火墙,查了一下资料,可以通过命令行netsh firewall来实现。封装了一个类来实现对允许放开的程序(Allowed program)进行管理。管理其他内容比如放开端口等方法是类似的。
程序中用到一个公共类 RunProcess,这个类可从我的另一篇文章 一个C#写的调用外部进程类 获得

namespace WinFirewall
{

public enum TScope
{
ALL,
SUBNET,
CUSTOM,
}

public enum TMode
{
ENABLE,
DISABLE,
}

/**//// <summary>
/// Manage the allowed program with the Windows Firewall.
/// </summary>
public class AllowedProgram
{
Set AllowedProgram Help#region Set AllowedProgram Help
/**//*
set allowedprogram

[ program = ] path
[ [ name = ] name
[ mode = ] ENABLE|DISABLE
[ scope = ] ALL|SUBNET|CUSTOM
[ addresses = ] addresses
[ profile = ] CURRENT|DOMAIN|STANDARD|ALL ]

Sets firewall allowed program configuration.

Parameters:

program - Program path and file name.

name - Program name (optional).

mode - Program mode (optional).
ENABLE - Allow through firewall (default).
DISABLE - Do not allow through firewall.

scope - Program scope (optional).
ALL - Allow all traffic through firewall (default).
SUBNET - Allow only local network (subnet) traffic through firewall.
CUSTOM - Allow only specified traffic through firewall.

addresses - Custom scope addresses (optional).

profile - Configuration profile (optional).
CURRENT - Current profile (default).
DOMAIN - Domain profile.
STANDARD - Standard profile.
ALL - All profiles.

Remarks: ''scope'' must be ''CUSTOM'' to specify ''addresses''.

Examples:

set allowedprogram C:\MyApp\MyApp.exe MyApp ENABLE

set allowedprogram C:\MyApp\MyApp.exe MyApp DISABLE

set allowedprogram C:\MyApp\MyApp.exe MyApp ENABLE CUSTOM

157.60.0.1,172.16.0.0/16,10.0.0.0/255.0.0.0,LocalSubnet
set allowedprogram program = C:\MyApp\MyApp.exe name = MyApp mode = ENABLE

set allowedprogram program = C:\MyApp\MyApp.exe name = MyApp mode = DISABLE
set allowedprogram program = C:\MyApp\MyApp.exe name = MyApp mode = ENABLE

scope = CUSTOM addresses =
157.60.0.1,172.16.0.0/16,10.0.0.0/255.0.0.0,LocalSubnet
*/
#endregion

private field#region private field
private String m_Program;
private String m_Name;
private TScope m_Scope = TScope.ALL;
private TMode m_Mode = TMode.ENABLE;
private String m_Address;
#endregion

public property#region public property
/**//// <summary>
/// Program path and file name.
/// </summary>
public String Program
{
get
{
return m_Program;
}

set
{
m_Program = value;
}
}

/**//// <summary>
/// Program name (optional).
/// </summary>
public String Name
{
get
{
return m_Name;
}

set
{
m_Name = value;
}
}

/**//// <summary>
/// Program scope (optional).
/// ALL - Allow all traffic through firewall (default).
/// SUBNET - Allow only local network (subnet) traffic through firewall.
/// CUSTOM - Allow only specified traffic through firewall. /// </summary>
public TScope Scope
{
get
{
return m_Scope;
}

set
{
m_Scope = value;
}
}

/**//// <summary>
/// Program mode (optional).
/// ENABLE - Allow throu

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号