import sys import os import os.path sys.path.append(os.path.join(os.environ['HOME'],'pox')) sys.path.append(os.path.join(os.getcwd(),'pox')) import pox.lib.packet as pktlib from pox.lib.packet import ethernet,ETHER_BROADCAST,IP_ANY from pox.lib.packet import arp,ipv4,icmp,unreach,udp,tcp from pox.lib.addresses import EthAddr,IPAddr,netmask_to_cidr,cidr_to_netmask,parse_cidr import time class Firewall(object): def __init__(self): # load the firewall_rules.txt file, initialize some data # structure(s) that hold the rule representations pass def tests(): f = Firewall() ip = ipv4() ip.srcip = IPAddr("172.16.42.1") ip.dstip = IPAddr("10.0.0.2") ip.protocol = 17 xudp = udp() xudp.srcport = 53 xudp.dstport = 53 xudp.payload = "Hello, world" xudp.len = 8 + len(xudp.payload) ip.payload = xudp print len(ip) # print the length of the packet, just for fun # you can name this method what ever you like, but you'll # need some method that gets periodically invoked for updating # token bucket state for any rules with rate limits f.update_token_buckets() # again, you can name your "checker" as you want, but the # idea here is that we call some method on the firewall to # test whether a given packet should be permitted or denied. assert(f.allow(ip) == True) # if you want to simulate a time delay and updating token buckets, # you can just call time.sleep and then update the buckets. time.sleep(0.5) f.update_token_buckets() if __name__ == '__main__': # only call tests() if this file gets invoked directly, # not if it is imported. tests()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question