资源简介
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图
相关资源
- Scratch源码
- E4A无障碍跨程序操作类库(带源码、
- 设备管理系统源码
- 安卓wifi直连app源码
- 我的世界源码(易语言版)
- labview编程软件滤波器以及编写程序设
- 我的界面(visual foxpro)源码
- 易语言:一键cf基址源码
- The Secret Path 3D 3D魔方迷宫[源码][scra
- scratch垃圾分类源码(最终版本).sb
- uboot到linux logo显示不间断 补丁
- 安卓QQ6.71协议源码易语言,qq协议源码
- 编译原理实验工具及参考源码(lex&
- E盾偷后台工具源码
- UNIX/LINUX编程实践教程的源码
- 十以内加减法练习 powerbuilder源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- 农场开发项目
- OCR源码
- PLC上位机编程软件
- 用foobar2000听google音乐[更新一下]
- 学生信息管理系统源码
- 用VC 编写的仿QQ聊天室程序源代码
- 毕业论文之温度传感器DS18B20(源码
- 可自定义导航网站源码
- 栅栏填充算法源码(VC)
- msp430F149操作红外接收模块源码
- [免费]图像识别c 源码
- 周易排盘源码
评论
共有 条评论