当前位置:首页 > 中科大高级计算机网络实验报告
防火墙实验报告
一.实验过程
1. 编写Python源代码,命名为pyretic_firewall.py。 保存在
~/pyretic/pyretic/examples中。
2. 编写firewall-policies.csv源文件。保存在~/pyretic/pyretic/examples中。 3. 在虚拟机mininet仿真器中创建网络拓扑。 4. 在宿主机中连接虚拟机,运行程序。 5. 运用tcpdump测试实验结果。
二.pyretic_firewall.py源代码及重要代码解释 from pyretic.lib.corelib import * from pyretic.lib.std import * #以上代码引用库函数
# insert the name of the module and policy you want to import from pyretic.examples.pyretic_switch import act_like_switch import os import csv
from csv import DictReader #以上代码引用自己所需的一些模块
policy_file = \os.environ[ 'HOME']
#以上代码为指定引用的文件的路径 #以下代码为main函数 def main():
# start with a policy that doesn't match any packets # 初始化not_allowed变量 not_allowed = none
# and sdd traffic that isn't allowed
# read the firewall-policies.csv #打开.csv文件并读取文件内容 with open(policy_file, \ dictreader = DictReader(csvfile)
#如果d在dictreader中,则添加到not_allowed 中 for d in dictreader:
#对不允许的路由进行匹配
not_allowed = not_allowed +
(match(srcmac=MAC(d['mac_0']))&match(dstmac=MAC(d['mac_1']))) + (match(srcmac=MAC(d['mac_1']))&match(dstmac=MAC(d['mac_0']))) #express allowed traffic in terms of not_allowed - hint use'~' #将不允许的路由取反即为允许路由 allowed = ~not_allowed
# and only send allowed traffic to the mac learning (act_like_switch) logic # 将允许的路由作为pyretic_switch中act_like_switch()的输入 return allowed>>act_like_switch() 三.firewall-policies.csv 文件内容:
四.运行结果截图及结果解释
(1)在虚拟机中运行程序,结果如下所示:
(2)打开Xming,利用Putty远程登录虚拟机:
登录后结果:
(3)创建含有6台Host的网络拓扑,命令及运行结果如下图:
(4)打开6台Host的xterm,结果如图:
(5)在终端4,5,6的xterm中,运行tcpdump:
(6)测试实验结果
① 用h1 ping h4 ,测试结果下图所示,h1 ping h4 失败,说明设置的防火墙生效。
共分享92篇相关文档