防火墙编程
1. linux下编写防火墙需要什么知识
实现基于iptables的防火墙,至少对这个东东有个整体的了解再下手。
1.确认iptables服务已经安装(多数Linux默认安装的)
2.启动iptables服务(service iptables start),如果没有反应,要到/etc/sysconfig下面touch 一个iptables文件。
3.配置iptables。(这个内容太多了,还是在网上找找教程吧,多得跟牛毛似的!)
还是举个例子,比如,你不想让192.168.10.0 的子网访问192.168.20.20这台www服务器,可以这样写:
#iptables -I INPUT -s 192.168.10.0/24 -d 192.168.20.20 -p tcp --dport 80 -j DROP
简单解释一下吧:
iptables是指令,不多说了
-I INPUT是向INPUT表里面插入一个记录
-s 192.168.10.0/24 是指定源地址
-d 192.168.20.20 是指定目的地址
-p tcp --dport 80 是协议和端口
-j DROP 是采取的动作,DROP就是抛弃。ACCETP就是接受。
2. C++编写防火墙
U盘防火墙工作量、技术含量、创新程度都不够,肯定会被退回去。
剩下的只有两个:包过滤防火墙软件和防火墙准系统。
包过滤防火墙的难点主要是在编写网卡的上层过滤驱动上,防火墙准系统会稍微简单些,做的工作是:
1.精简linux内核,只留下路由、iptables、shell、telnet。
2.设计一些常用的iptables规则模板,在写个shell前端以便管理员应用这些规则。
3.设置相应的权限使远程访问者只能运行你的前端。
这样防火墙准系统就完成了,除了一点点shell编程以外就没编程了。即使是这样只要你能做出来铁定拿优秀毕业设计。
3. java编程:用java做一个简单的防火墙思路:
java.net
类:DatagramPacket
DatagramSocket
或者:ServerSocket
Socket
这些类都有一个返回端口的方法,ServerSocket是getLocalPort() ,其他三个是getPort()。如果返回的端口是80,那么就禁止接收或者发送数据,并给与适当的提示信息。
4. 在Vista中怎么编程控制防火墙设定
前面哪个说了一半后面没有说清楚 FireWallManager 程式主要功能有 1. public void FireWallTrigger ( bool enable ) // 开关防火墙。 1. public void FireWallTrigger ( bool enable ) // 开关防火墙。 貌似在 Vista 裏面有问题, XP sp2 好像可以。 貌似在 Vista 里面有问题, XP sp2 好像可以。 但是用 INetFwPolicy2.set_FirewallEnabled 的方法的话, Vista 也能搞定。 但是用 INetFwPolicy2.set_FirewallEnabled 的方法的话, Vista 也能搞定。 2. public void FireWallService ( string name , bool enable ) // 开关防火墙服务程式,一般裏面的 File and Printer Sharing 服务比较有用。 2. public void FireWallService ( string name , bool enable ) // 开关防火墙服务程式,一般里面的 File and Printer Sharing 服务比较有用。 3. public bool AddPort ( string portName , int portNumber , string protocol ) // 开启一个端口。 3. public bool AddPort ( string portName , int portNumber , string protocol ) // 开启一个端口。 4. public bool RemovePort ( int portNumber , string protocol ) // 删除开启的端口 4. public bool RemovePort ( int portNumber , string protocol ) // 删除开启的端口 5. public bool AddAplication ( string discriptionName , string fileName ) // 开启放行应用程式 5. public bool AddAplication ( string discriptionName , string fileName ) // 开启放行应用程式 6. public bool RemoveApplication ( string fileName ) // 关闭放行的应用程式。 6. public bool RemoveApplication ( string fileName ) // 关闭放行的应用程式。 裏面还有个 protected Object getInstance ( String typeName ) 本来是用 CLSID 来实例化那些接口的,后来发现 ProgID 其实更简单,不需要查,裏面有个规律,只需把接口的 INet 删掉就是 ProgID 了。 里面还有个 protected Object getInstance ( String typeName )本来是用 CLSID 来实例化那些接口的,后来发现 ProgID 其实更简单,不需要查,里面有个规律,只需把接口的 INet 删掉就是 ProgID 了。 如 INetFwOpenPort port = ( INetFwOpenPort ) Activator.CreateInstance ( Type.GetTypeFromProgID ( "HNetCfg.FwOpenPort" ) ); 中 INetFwOpenPort 与 FwOpenPort. 如 INetFwOpenPort port = ( INetFwOpenPort ) Activator.CreateInstance ( Type.GetTypeFromProgID ( "HNetCfg.FwOpenPort" ) );中 INetFwOpenPort 与 FwOpenPort. 首先,创建一个 Console 程式,在程式中添加引用,在 COM 物件中找到 "NetFwTypeLib" ,添加即可。 首先,创建一个 Console 程式,在程式中添加引用,在 COM 物件中找到 "NetFwTypeLib" ,添加即可。 防火墙主要是靠这个对象操作的。 防火墙主要是靠这个对象操作的。 貌似不止 Vista , Xp 也是一样的。 貌似不止 Vista , Xp 也是一样的。 核心程式如下: 核心程式如下: FireWallManager.cs FireWallManager.cs using System; using System; using System.Collections.Generic; using System.Collections.Generic; using System.Text; using System.Text; using NetFwTypeLib; using NetFwTypeLib; namespace FirewallManager namespace FirewallManager { { class FwManager class FwManager { { private INetFwMgr NetFwMgr; private INetFwMgr NetFwMgr; private INetFwProfile NetFwProfile; private INetFwProfile NetFwProfile; private INetFwPolicy2 NetFwPolicy2; //this interface contains lots of usefull functions . private INetFwPolicy2 NetFwPolicy2; //this interface contains lots of usefull functions . public FwManager() public FwManager() { { //Create Com Object //Create Com Object //Type NetFwMgrType = Type.GetTypeFromCLSID( new Guid( "{304CE942-6E39-40D8 //Type NetFwMgrType = Type.GetTypeFromCLSID( new Guid( "{304CE942-6E39-40D8 -943A -943A -B -B 913C 913C 40C 40C 9CD4}" ) ); 9CD4}" ) ); Type NetFwMgrType = Type.GetTypeFromProgID( "HNetCfg.FwMgr" ); Type NetFwMgrType = Type.GetTypeFromProgID( "HNetCfg.FwMgr" ); object NetFwMgrObject = Activator.CreateIn object NetFwMgrObject = Activator.CreateIn stance( NetFwMgrType ); stance( NetFwMgrType ); NetFwMgr = ( INetFwMgr )NetFwMgrObject; NetFwMgr = ( INetFwMgr )NetFwMgrObject; NetFwProfile = NetFwMgr.LocalPolicy.CurrentProfile; NetFwProfile = NetFwMgr.LocalPolicy.CurrentProfile; Type NetFwPolicy2Type = Type.GetTypeFromProgID( "HNetCfg.FwPolicy2" ); Type NetFwPolicy2Type = Type.GetTypeFromProgID( "HNetCfg.FwPolicy2" ); object NetFwPolicy2Object = System.Activator.CreateInstance( NetFwPolicy2Type ); object NetFwPolicy2Object = System.Activator.CreateInstance( NetFwPolicy2Type ); NetFwPolicy2 = ( INetFwPolicy2 )NetFwPolicy2Object; NetFwPolicy2 = ( INetFwPolicy2 )NetFwPolicy2Object; } } public void ShowInfo() public void ShowInfo() { { switch( NetFwProfile.Type ) switch( NetFwProfile.Type ) { { case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_DOMAIN: case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_DOMAIN: Console.WriteLine( "Network Profile Type1: " + "Domain" ); Console.WriteLine( "Network Profile Type1: " + "Domain" ); break; break; case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_STANDARD: case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_STANDARD: Console.WriteLine( "Network Profile Type1: " + "Standard" ); Console.WriteLine( "Network Profile Type1: " + "Standard" ); break; break; case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_CURRENT: case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_CURRENT: Console.WriteLine( "Network Profile Type1: " + "Current" ); Console.WriteLine( "Network Profile Type1: " + "Current" ); break; break; case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_TYPE_MAX: case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_TYPE_MAX: Console.WriteLine( "Network Profile Type1: " + "Max" ); Console.WriteLine( "Network Profile Type1: " + "Max" ); break; break; } } switch( ( NET_FW_PROFILE_TYPE2_ )NetFwPolicy2.CurrentProfileTypes ) switch( ( NET_FW_PROFILE_TYPE2_ )NetFwPolicy2.CurrentProfileTypes ) { { case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_DOMAIN: case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_DOMAIN: Console.WriteLine( "Network Profile Type2: " + "Domain" ); Console.WriteLine( "Network Profile Type2: " + "Domain" ); break; break; case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PRIVATE: case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PRIVATE: Console.WriteLine( "Network Profile Type2: " + "Private" ); Console.WriteLine( "Network Profile Type2: " + "Private" ); break; break; case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC: case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC: Console.WriteLine( "Network Profile Type2: " + "Public" ); Console.WriteLine( "Network Profile Type2: " + "Public" ); break; break; case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_ALL: case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_ALL: Console.WriteLine( "Network Profile Type2: " + "All" ); Console.WriteLine( "Network Profile Type2: " + "All" ); break; break; } } Console.WriteLine( "Firewall Enabled: " + NetFwProfile.FirewallEnabled ); Console.WriteLine( "Firewall Enabled: " + NetFwProfile.FirewallEnabled ); Console.WriteLine( "Exceptions Not Allowed: " + NetFwProfile.ExceptionsNotAllowed ); Console.WriteLine( "Exceptions Not Allowed: " + NetFwProfile.ExceptionsNotAllowed ); Console.WriteLine( "Notifications Disabled: " + NetFwProfile.NotificationsDisabled ); Console.WriteLine( "Notifications Disabled: " + NetFwProfile.NotificationsDisabled ); //Console.WriteLine(": " + NetFwProfile.); //Console.WriteLine(": " + NetFwProfile.); //Remote Admin //Remote Admin INetFwRemoteAdminSettings RASettings = NetFwP INetFwRemoteAdminSettings RASettings = NetFwP rofile.RemoteAdminSettings; rofile.RemoteAdminSettings; Console.WriteLine( "Remote Administration Enabled: " + RASettings.Enabled ); Console.WriteLine( "Remote Administration Enabled: " + RASettings.Enabled ); switch( RASettings.IpVersion ) switch( RASettings.IpVersion ) { { case NET_FW_IP_VERSION_.NET_FW_IP_VERSION_V4: case NET_FW_IP_VERSION_.NET_FW_IP_VERSION_V4: Console.WriteLine( "Remote Administration IP Version: V4" ); Console.WriteLine( "Remote Administration IP Version: V4" ); break; break; case NET_FW_IP_VERSION_.NET_FW_IP_VERSION_V6: case NET_FW_IP_VERSION_.NET_FW_IP_VERSION_V6: Console.WriteLine( "Remote Administration IP Version: V6" ); Console.WriteLine( "Remote Administration IP Version: V6" ); break; break; case NET_FW_IP_VERSION_.NET_FW_IP_VERSION_MAX: case NET_FW_IP_VERSION_.NET_FW_IP_VERSION_MAX: Console.WriteLine( "Remote Administration IP Version: MAX" ); Console.WriteLine( "Remote Administration IP Version: MAX" ); break; break; case NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY: case NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY: Console.WriteLine( "Remote Administration IP Version: ANY" ); Console.WriteLine( "Remote Administration IP Version: ANY" ); break; break; } } switch( RASettings.Scope ) switch( RASettings.Scope ) { { case NET_FW_SCOPE_.NET_FW_SCOPE_ALL: case NET_FW_SCOPE_.NET_FW_SCOPE_ALL: Console.WriteLine( "Remote Administration Scope: ALL" ); Console.WriteLine( "Remote Administration Scope: ALL" ); break; break; case NET_FW_SCOPE_.NET_FW_SCOPE_CUSTOM: case NET_FW_SCOPE_.NET_FW_SCOPE_CUSTOM: Console.WriteLine( "Remote Administration Scope: Custom" ); Console.WriteLine( "Remote Administration Scope: Custom" ); break; break; case NET_FW_SCOPE_.NET_FW_SCOPE_LOCAL_SUBNET: case NET_FW_SCOPE_.NET_FW_SCOPE_LOCAL_SUBNET: Console.WriteLine( "Remote Administration Scope: Local Subnet" ); Console.WriteLine( "Remote Administration Scope: Local Subnet" ); break; break; case NET_FW_SCOPE_.NET_FW_SCOPE_MAX: case NET_FW_SCOPE_.NET_FW_SCOPE_MAX: Console.WriteLine( "Remote Administration Scope: MAX" ); Console.WriteLine( "Remote Administration Scope: MAX" ); break; break; } }
5. 我想用c++编写一个防火墙,要求不是特别简单的,但是也不是特别难的,用来找个好工作的,现在小弟即将毕业
如果你给我分,我可以告诉你···
防火墙分为很多级别,从驱动级到应用层级别都可以
介于你时间较短,去研究windows内核驱动比较困难
我推荐你尝试在linux下完成防火墙工作,因为linux下的防火墙要容易编写很多,而且网上很多开源代码,防火墙基本功能很容易实现,主要难在对攻击行为的分析,C++可以写,C可以写,汇编也可以写,C++镶嵌C再镶嵌汇编都是可以的,别听1楼得,他没有理解C++和C的本质
6. 使用哪一种语言编程防火墙比较简单
JAVA。。不推荐吧。。
还是汇编语言好啊~~~~
效率高
C++饿。。TU都看的头大了
上次错误找半天发现封号没打 昏迷
7. 防火墙的编程语言是什么
通常是嵌入式操作系统vxworks,linux,+C语言
8. 怎么用JAVA编程一个防火墙
java.net
类:datagrampacket
datagramsocket
或者:serversocket
socket
这些类都有一个返回端口的方法,serversocket是getlocalport()
,其他三个是getport()。如果返回的端口是80,那么就禁止接收或者发送数据,并给与适当的提示信息。
9. 电脑防火墙会不会影响编程软件
有些会有影响,有些不会 ,这要看你的编程软件是否影响到了电脑的正常程序,如果影响到了有些软件就会直接拦下 ,而一些比较弱的防火墙应该不会拦截