本文整理汇总了Python中netfilter.rule.Rule类的典型用法代码示例。如果您正苦于以下问题:Python Rule类的具体用法?Python Rule怎么用?Python Rule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMatchState
def testMatchState(self):
print('Running Test Match State...')
rule = Rule(jump='ACCEPT')
rule.matches.append(Match('state', '--state ESTABLISHED,RELATED'))
print('\tRule: ' + str(rule))
self.assertEqual(rule.specbits(), ['-m', 'state', '--state', 'ESTABLISHED,RELATED', '-j', 'ACCEPT'])
print('...Done')
示例2: testMatchMultiportDports
def testMatchMultiportDports(self):
print('Running Test Match Mulitport Dports...')
rule = Rule(jump='ACCEPT')
rule.matches.append(Match('multiport', '--dports 20,21,22,80,25,1720'))
print('\tRule: ' + str(rule))
self.assertEqual(rule.specbits(), ['-m', 'multiport', '--dports', '20,21,22,80,25,1720', '-j', 'ACCEPT'])
print('...Done')
示例3: testMatchTos
def testMatchTos(self):
print('Running Test Match TOS...')
rule = Rule(jump='ACCEPT')
rule.matches.append(Match('tos', '--tos 0x10'))
print('\tRule: ' + str(rule))
self.assertEqual(rule.specbits(), ['-m', 'tos', '--tos', '0x10', '-j', 'ACCEPT'])
print('...Done')
示例4: testMatchTcpSport
def testMatchTcpSport(self):
print('Running Test Match TCP SPort...')
rule = Rule(protocol='tcp', jump='ACCEPT')
rule.matches.append(Match('tcp', '--sport 1234'))
print('\tRule: ' + str(rule))
self.assertEqual(rule.specbits(), ['-p', 'tcp', '-m', 'tcp', '--sport', '1234', '-j', 'ACCEPT'])
print('...Done')
示例5: testMatchMark
def testMatchMark(self):
print('Running Test Match Mark...')
rule = Rule(jump='ACCEPT')
rule.matches.append(Match('mark', '--mark 0x64'))
print('\tRule: ' + str(rule))
self.assertEqual(rule.specbits(), ['-m', 'mark', '--mark', '0x64', '-j', 'ACCEPT'])
print('...Done')
示例6: testMatchTcpFlags
def testMatchTcpFlags(self):
print('Running Test Match TCP Flags...')
rule = Rule(protocol='tcp', jump='ACCEPT')
rule.matches.append(Match('tcp', '--tcp-flags ACK,SYN ACK'))
print('\tRule: ' + str(rule))
self.assertEqual(rule.specbits(), ['-p', 'tcp', '-m', 'tcp', '--tcp-flags', 'ACK,SYN', 'ACK', '-j', 'ACCEPT'])
print('...Done')
示例7: testInterfaces
def testInterfaces(self):
rule = Rule(in_interface="eth1", out_interface="eth2", jump="REJECT")
self.assertEqual(rule.protocol, None)
self.assertEqual(rule.in_interface, "eth1")
self.assertEqual(rule.out_interface, "eth2")
self.assertEqual(rule.source, None)
self.assertEqual(rule.destination, None)
self.assertEqual(rule.specbits(), ["-i", "eth1", "-o", "eth2", "-j", "REJECT"])
示例8: testInterfacesNegated
def testInterfacesNegated(self):
rule = Rule(in_interface='!eth1', out_interface='!eth2',
jump='REJECT')
self.assertEqual(rule.protocol, None)
self.assertEqual(rule.in_interface, '!eth1')
self.assertEqual(rule.out_interface, '!eth2')
self.assertEqual(rule.source, None)
self.assertEqual(rule.destination, None)
self.assertEqual(rule.specbits(), ['!', '-i', 'eth1', '!', '-o', 'eth2', '-j', 'REJECT'])
示例9: testSourceDestinationProtocol
def testSourceDestinationProtocol(self):
rule = Rule(source="192.168.1.2", destination="192.168.1.3", protocol="tcp", jump="DROP")
self.assertEqual(rule.protocol, "tcp")
self.assertEqual(rule.in_interface, None)
self.assertEqual(rule.out_interface, None)
self.assertEqual(rule.source, "192.168.1.2")
self.assertEqual(rule.destination, "192.168.1.3")
self.assertEqual(rule.jump.name(), "DROP")
self.assertEqual(rule.jump.options(), {})
self.assertEqual(rule.specbits(), ["-p", "tcp", "-s", "192.168.1.2", "-d", "192.168.1.3", "-j", "DROP"])
示例10: testSource
def testSource(self):
rule = Rule(source="192.168.1.2", jump="ACCEPT")
self.assertEqual(rule.protocol, None)
self.assertEqual(rule.in_interface, None)
self.assertEqual(rule.out_interface, None)
self.assertEqual(rule.source, "192.168.1.2")
self.assertEqual(rule.destination, None)
self.assertEqual(rule.jump.name(), "ACCEPT")
self.assertEqual(rule.jump.options(), {})
self.assertEqual(rule.specbits(), ["-s", "192.168.1.2", "-j", "ACCEPT"])
示例11: testInit
def testInit(self):
rule = Rule(jump=Target('ACCEPT'))
self.assertEqual(rule.protocol, None)
self.assertEqual(rule.in_interface, None)
self.assertEqual(rule.out_interface, None)
self.assertEqual(rule.source, None)
self.assertEqual(rule.destination, None)
self.assertEqual(rule.jump.name(), 'ACCEPT')
self.assertEqual(rule.jump.options(), {})
self.assertEqual(rule.specbits(), ['-j', 'ACCEPT'])
示例12: testSourceNegated
def testSourceNegated(self):
rule = Rule(source='! 192.168.1.2', jump='ACCEPT')
self.assertEqual(rule.protocol, None)
self.assertEqual(rule.in_interface, None)
self.assertEqual(rule.out_interface, None)
self.assertEqual(rule.source, '! 192.168.1.2')
self.assertEqual(rule.destination, None)
self.assertEqual(rule.jump.name(), 'ACCEPT')
self.assertEqual(rule.jump.options(), {})
self.assertEqual(rule.specbits(), ['!', '-s', '192.168.1.2', '-j', 'ACCEPT'])
示例13: testDestination
def testDestination(self):
rule = Rule(destination="192.168.1.3", jump="REJECT")
self.assertEqual(rule.protocol, None)
self.assertEqual(rule.in_interface, None)
self.assertEqual(rule.out_interface, None)
self.assertEqual(rule.source, None)
self.assertEqual(rule.destination, "192.168.1.3")
self.assertEqual(rule.jump.name(), "REJECT")
self.assertEqual(rule.jump.options(), {})
self.assertEqual(rule.specbits(), ["-d", "192.168.1.3", "-j", "REJECT"])
示例14: testDestinationNegated
def testDestinationNegated(self):
rule = Rule(destination='! 192.168.1.3', jump='REJECT')
self.assertEqual(rule.protocol, None)
self.assertEqual(rule.in_interface, None)
self.assertEqual(rule.out_interface, None)
self.assertEqual(rule.source, None)
self.assertEqual(rule.destination, '! 192.168.1.3')
self.assertEqual(rule.jump.name(), 'REJECT')
self.assertEqual(rule.jump.options(), {})
self.assertEqual(rule.specbits(), ['!', '-d', '192.168.1.3', '-j', 'REJECT'])
示例15: testSourceDestinationProtocol
def testSourceDestinationProtocol(self):
rule = Rule(source='192.168.1.2', destination='192.168.1.3',
protocol='tcp', jump='DROP')
self.assertEqual(rule.protocol, 'tcp')
self.assertEqual(rule.in_interface, None)
self.assertEqual(rule.out_interface, None)
self.assertEqual(rule.source, '192.168.1.2')
self.assertEqual(rule.destination, '192.168.1.3')
self.assertEqual(rule.jump.name(), 'DROP')
self.assertEqual(rule.jump.options(), {})
self.assertEqual(rule.specbits(), ['-p', 'tcp', '-s', '192.168.1.2', '-d', '192.168.1.3', '-j', 'DROP'])