資源簡介
linux iptables 源碼

代碼片段和文件信息
#!/usr/bin/python
#
#?(C)?2012-2013?by?Pablo?Neira?Ayuso?
#
#?This?program?is?free?software;?you?can?redistribute?it?and/or?modify
#?it?under?the?terms?of?the?GNU?General?Public?License?as?published?by
#?the?Free?Software?Foundation;?either?version?2?of?the?License?or
#?(at?your?option)?any?later?version.
#
#?This?software?has?been?sponsored?by?Sophos?Astaro?
#
import?sys
import?os
import?subprocess
import?argparse
IPTABLES?=?“iptables“
IP6TABLES?=?“ip6tables“
#IPTABLES?=?“xtables?-4“
#IP6TABLES?=?“xtables?-6“
IPTABLES_SAVE?=?“iptables-save“
IP6TABLES_SAVE?=?“ip6tables-save“
#IPTABLES_SAVE?=?[‘xtables-save‘‘-4‘]
#IP6TABLES_SAVE?=?[‘xtables-save‘‘-6‘]
EXTENSIONS_PATH?=?“extensions“
LOGFILE=“/tmp/iptables-test.log“
log_file?=?None
class?Colors:
????HEADER?=?‘\033[95m‘
????BLUE?=?‘\033[94m‘
????GREEN?=?‘\033[92m‘
????YELLOW?=?‘\033[93m‘
????RED?=?‘\033[91m‘
????ENDC?=?‘\033[0m‘
def?print_error(reason?filename=None?lineno=None):
????‘‘‘
????Prints?an?error?with?nice?colors?indicating?file?and?line?number.
????‘‘‘
????print?(filename?+?“:?“?+?Colors.RED?+?“ERROR“?+
????????Colors.ENDC?+?“:?line?%d?(%s)“?%?(lineno?reason))
def?delete_rule(iptables?rule?filename?lineno):
????‘‘‘
????Removes?an?iptables?rule
????‘‘‘
????cmd?=?iptables?+?“?-D?“?+?rule
????ret?=?execute_cmd(cmd?filename?lineno)
????if?ret?==?1:
????????reason?=?“cannot?delete:?“?+?iptables?+?“?-I?“?+?rule
????????print_error(reason?filename?lineno)
????????return?-1
????return?0
def?run_test(iptables?rule?rule_save?res?filename?lineno):
????‘‘‘
????Executes?an?unit?test.?Returns?the?output?of?delete_rule().
????Parameters:
????:param??iptables:?string?with?the?iptables?command?to?execute
????:param?rule:?string?with?iptables?arguments?for?the?rule?to?test
????:param?rule_save:?string?to?find?the?rule?in?the?output?of?iptables?-save
????:param?res:?expected?result?of?the?rule.?Valid?values:?“OK“?“FAIL“
????:param?filename:?name?of?the?file?tested?(used?for?print_error?purposes)
????:param?lineno:?line?number?being?tested?(used?for?print_error?purposes)
????‘‘‘
????ret?=?0
????cmd?=?iptables?+?“?-A?“?+?rule
????ret?=?execute_cmd(cmd?filename?lineno)
????#
????#?report?failed?test
????#
????if?ret:
????????if?res?==?“OK“:
????????????reason?=?“cannot?load:?“?+?cmd
????????????print_error(reason?filename?lineno)
????????????return?-1
????????else:
????????????#?do?not?report?this?error
????????????return?0
????else:
????????if?res?==?“FAIL“:
????????????reason?=?“should?fail:?“?+?cmd
????????????print_error(reason?filename?lineno)
????????????delete_rule(iptables?rule?filename?lineno)
????????????return?-1
????matching?=?0
????splitted?=?iptables.split(“?“)
????if?len(splitted)?==?2:
????????if?splitted[1]?==?‘-4‘:
????????????command?=?IPTABLES_SAVE
????????elif?splitted[1]?==?‘-6‘:
????????????command?=?IP6TABLES_SAVE
????elif?len(splitted)?==?1:
????????if?splitted[0]?==?IPTABLES:
????????????command?=
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????207??2015-05-08?07:02??iptables-master\.gitignore
?????文件?????????54??2015-05-08?07:02??iptables-master\autogen.sh
?????文件????????863??2015-05-08?07:02??iptables-master\COMMIT_NOTES
?????文件???????8588??2015-05-08?07:02??iptables-master\configure.ac
?????文件??????18092??2015-05-08?07:02??iptables-master\COPYING
?????文件???????1362??2015-05-08?07:02??iptables-master\etc\ethertypes
?????文件???????2018??2015-05-08?07:02??iptables-master\etc\xtables.conf
?????文件?????????79??2015-05-08?07:02??iptables-master\extensions\.gitignore
?????文件???????1395??2015-05-08?07:02??iptables-master\extensions\dscp_helper.c
?????文件???????8963??2015-05-08?07:02??iptables-master\extensions\GNUmakefile.in
?????文件???????5428??2015-05-08?07:02??iptables-master\extensions\libarpt_mangle.c
?????文件???????3200??2015-05-08?07:02??iptables-master\extensions\libebt_802_3.c
?????文件???????7980??2015-05-08?07:02??iptables-master\extensions\libebt_ip.c
?????文件???????4377??2015-05-08?07:02??iptables-master\extensions\libebt_limit.c
?????文件???????5005??2015-05-08?07:02??iptables-master\extensions\libebt_log.c
?????文件???????5525??2015-05-08?07:02??iptables-master\extensions\libebt_mark.c
?????文件???????2660??2015-05-08?07:02??iptables-master\extensions\libebt_mark_m.c
?????文件???????4046??2015-05-08?07:02??iptables-master\extensions\libebt_nflog.c
?????文件???????3286??2015-05-08?07:02??iptables-master\extensions\libip6t_ah.c
?????文件????????302??2015-05-08?07:02??iptables-master\extensions\libip6t_ah.man
?????文件????????456??2015-05-08?07:02??iptables-master\extensions\libip6t_ah.t
?????文件???????6359??2015-05-08?07:02??iptables-master\extensions\libip6t_DNAT.c
?????文件????????330??2015-05-08?07:02??iptables-master\extensions\libip6t_DNAT.t
?????文件???????2426??2015-05-08?07:02??iptables-master\extensions\libip6t_DNPT.c
?????文件????????980??2015-05-08?07:02??iptables-master\extensions\libip6t_DNPT.man
?????文件????????208??2015-05-08?07:02??iptables-master\extensions\libip6t_DNPT.t
?????文件???????4716??2015-05-08?07:02??iptables-master\extensions\libip6t_dst.c
?????文件????????317??2015-05-08?07:02??iptables-master\extensions\libip6t_dst.man
?????文件????????172??2015-05-08?07:02??iptables-master\extensions\libip6t_dst.t
?????文件????????363??2015-05-08?07:02??iptables-master\extensions\libip6t_eui64.c
............此處省略512個文件信息
- 上一篇:中英文對照論文
- 下一篇:超市管理系統E-R圖
評論
共有 條評論