资源简介
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图
相关资源
- linux安全加固
- EDULINE在线教育系统
- IBM SPSS 25 序列号Windows、macOS、Linux适用
- 基于AT89S52的红外巡线小车源码
- linux多线程实现矩阵乘法
- 基站定位和WIFI定位完美结合项目源码
- Linux基础及应用教程(基于CentOS 7)
- 利用钩子技术控制进程创建(源码)
- linux实验七 shell编程
- linux实验四_文件目录操作命令
- 井字棋源码+程序报告
- flash游戏中控制角色移动的源代码
- web页面中的打分源码
- webcam_v4l2_x264
- jbig图像压缩算法源码
- 官方jdk1.8.0U201 for Linux 32位和64位
- Linux酒店客房管理系统shell实现
- 51旅游微信小城序源码
- flappyBird193199
- 网狐6603内核引擎源码(免积分)
- 叠方块游戏源码2012929
- 汽车票订票系统源码20110803
- 博客BLOG
- QT串口编程库--qextserialport-1.2win-alpha
- qq邮箱源码
- linux操作系统第二版 习题答案
- 百度贴吧爱丽丝源码
- Haproxy安装脚本
- 微票-微信小程序源码
- linux下dhcp安装包
评论
共有 条评论