防火牆編程
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. 電腦防火牆會不會影響編程軟體
有些會有影響,有些不會 ,這要看你的編程軟體是否影響到了電腦的正常程序,如果影響到了有些軟體就會直接攔下 ,而一些比較弱的防火牆應該不會攔截