示例#1
0
class HushPacketConsumer(object):

     implements(interfaces.IConsumer)
     mtu = 600

     def __init__(self, dest_ip):
          self.dest_ip          = dest_ip
          self.ip_packet_writer = IPPacketWriter(dest_ip)
          self.producer         = None

     def registerProducer(self, producer, streaming):
          assert self.producer is None
          assert streaming is True

          self.producer = producer
          self.ip_packet_writer.start()

     def unregisterProducer(self):
          assert self.producer is not None
          self.producer.stop_reading()
          self.ip_packet_writer.stop()

     def write(self, packet):
          self.ip_packet_writer.write(self.encodeHushPacket(packet))

     def encodeHushPacket(self, packet):
          if len(packet) > HushPacketConsumer.mtu:
               raise HushPacketMTUException
          ip   = IP(dst  = self.dest_ip)
          icmp = ICMP(type=0)
          encoded_packet = str(ip/icmp/packet)
          return encoded_packet
示例#2
0
 def __init__(self, dest_ip):
      self.dest_ip          = dest_ip
      self.ip_packet_writer = IPPacketWriter(dest_ip)
      self.producer         = None