예제 #1
0
 def status(self):
     raw = self.getter()
     r = OrderedDict([('raw', repr(raw))])
     if raw:
         frame = Frame(raw)
         r['Frame'] = OrderedDict([
             ('Dst MAC', '{:02x}'.format(mac_from_bytes(frame.dst))),
             ('Src MAC', '{:02x}'.format(mac_from_bytes(frame.src))),
             ('EtherType', Frame.EtherType[frame.ethertype]),
         ])
         if frame.ethertype == Frame.EtherType.IPv4:
             packet = Packet(frame.payload)
             r['IPv4'] = OrderedDict([
                 ('Protocol', Packet.Protocol[packet.protocol]),
                 ('Src IP', ip_to_str(packet.src)),
                 ('Dst IP', ip_to_str(packet.dst)),
                 ('Payload', repr(packet.payload)),
             ])
         elif frame.ethertype == Frame.EtherType.ARP:
             arp = ARP(frame.payload)
             r['ARP'] = OrderedDict([
                 ('Oper', ARP.Oper[arp.oper]),
                 ('Src IP', ip_to_str(arp.src_ip)),
                 ('Src MAC', '{:02x}'.format(mac_from_bytes(arp.src_mac))),
                 ('Dst IP', ip_to_str(arp.dst_ip)),
                 ('Dst MAC', '{:02x}'.format(mac_from_bytes(arp.dst_mac))),
             ])
     return r
예제 #2
0
파일: pdus.py 프로젝트: fans656/mint-dev
 def status(self):
     raw = self.getter()
     r = OrderedDict([('raw', repr(raw))])
     if raw:
         frame = Frame(raw)
         r['Frame'] = OrderedDict([
             ('Dst MAC', '{:02x}'.format(mac_from_bytes(frame.dst))),
             ('Src MAC', '{:02x}'.format(mac_from_bytes(frame.src))),
             ('EtherType', Frame.EtherType[frame.ethertype]),
         ])
         if frame.ethertype == Frame.EtherType.IPv4:
             packet = Packet(frame.payload)
             r['IPv4'] = OrderedDict([
                 ('Protocol', Packet.Protocol[packet.protocol]),
                 ('Src IP', ip_to_str(packet.src)),
                 ('Dst IP', ip_to_str(packet.dst)),
                 ('Payload', repr(packet.payload)),
             ])
         elif frame.ethertype == Frame.EtherType.ARP:
             arp = ARP(frame.payload)
             r['ARP'] = OrderedDict([
                 ('Oper', ARP.Oper[arp.oper]),
                 ('Src IP', ip_to_str(arp.src_ip)),
                 ('Src MAC', '{:02x}'.format(mac_from_bytes(arp.src_mac))),
                 ('Dst IP', ip_to_str(arp.dst_ip)),
                 ('Dst MAC', '{:02x}'.format(mac_from_bytes(arp.dst_mac))),
             ])
     return r
예제 #3
0
 def status(self):
     r = OrderedDict()
     for addr, entry in self.route_table.items():
         addr = '{:02x}'.format(mac_from_bytes(addr))
         ports = map(lambda p: self.ports.index(p), entry.ports)
         time = entry.time
         r[addr] = '{} {}'.format(ports, time)
     return r
예제 #4
0
파일: framer.py 프로젝트: ver007/mint-dev
 def run(self):
     while True:
         raw = self.delimiter.recv()
         frame = Frame(raw)
         if self.for_me(frame.dst):
             try:
                 handler = self.handlers[frame.ethertype]
             except KeyError:
                 mint.report('no handler for {}'.format(
                     Frame.EtherType[frame.ethertype]))
             else:
                 handler(frame.payload)
         else:
             msg = '{:02x} dropped frame from {:02x} to {:02x}: {}'
             mint.report(
                 msg.format(mac_from_bytes(self.mac),
                            mac_from_bytes(frame.src),
                            mac_from_bytes(frame.dst), repr(frame.payload)))
예제 #5
0
파일: framer.py 프로젝트: fans656/mint-dev
 def run(self):
     while True:
         raw = self.delimiter.recv()
         frame = Frame(raw)
         if self.for_me(frame.dst):
             try:
                 handler = self.handlers[frame.ethertype]
             except KeyError:
                 mint.report('no handler for {}'.format(
                     Frame.EtherType[frame.ethertype]
                 ))
             else:
                 handler(frame.payload)
         else:
             msg = '{:02x} dropped frame from {:02x} to {:02x}: {}'
             mint.report(msg.format(
                 mac_from_bytes(self.mac),
                 mac_from_bytes(frame.src),
                 mac_from_bytes(frame.dst),
                 repr(frame.payload)
             ))
예제 #6
0
 def register(self, addr, port):
     mint.report('register host with address {:02x} on port-{}',
                 mac_from_bytes(addr), self.ports.index(port))
     if addr == '\x00':
         return
     self.route_table[addr] = bunch(ports=[port], time=mint.now())
예제 #7
0
 def mac(self):
     return mac_from_bytes(self.framer.mac)