예제 #1
0
 def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None, nofilter=0):
     self.type = type
     self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
     self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)
     flush_fd(self.ins)
     if iface:
         self.ins.bind((iface, type))
     if not nofilter:
         if conf.except_filter:
             if filter:
                 filter = "(%s) and not (%s)" % (filter, conf.except_filter)
             else:
                 filter = "not (%s)" % conf.except_filter
         if filter is not None:
             attach_filter(self.ins, filter)
     self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2**30)
     self.outs = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
     self.outs.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30)
     if promisc is None:
         promisc = conf.promisc
     self.promisc = promisc
     if self.promisc:
         if iface is None:
             self.iff = get_if_list()
         else:
             if iface.__class__ is list:
                 self.iff = iface
             else:
                 self.iff = [iface]
         for i in self.iff:
             set_promisc(self.ins, i)
예제 #2
0
 def __init__(self, iface=None, type=ETH_P_ALL, filter=None, nofilter=0):
     if iface is None:
         iface = conf.iface
     self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                              socket.htons(type))
     self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)
     flush_fd(self.ins)
     if not nofilter:
         if conf.except_filter:
             if filter:
                 filter = "(%s) and not (%s)" % (filter, conf.except_filter)
             else:
                 filter = "not (%s)" % conf.except_filter
         if filter is not None:
             attach_filter(self.ins, filter)
     self.ins.bind((iface, type))
     self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2**30)
     self.outs = self.ins
     self.outs.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30)
     sa_ll = self.outs.getsockname()
     if sa_ll[3] in conf.l2types:
         self.LL = conf.l2types[sa_ll[3]]
     elif sa_ll[1] in conf.l3types:
         self.LL = conf.l3types[sa_ll[1]]
     else:
         warning(
             "Unable to guess type (interface=%s protocol=%#x family=%i). Using Ethernet"
             % (sa_ll[0], sa_ll[1], sa_ll[3]))
         self.LL = Ether
예제 #3
0
 def __init__(self, iface = None, type = ETH_P_ALL, filter=None, nofilter=0):
     if iface is None:
         iface = conf.iface
     self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
     self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)
     flush_fd(self.ins)
     if not nofilter: 
         if conf.except_filter:
             if filter:
                 filter = "(%s) and not (%s)" % (filter, conf.except_filter)
             else:
                 filter = "not (%s)" % conf.except_filter
         if filter is not None:
             attach_filter(self.ins, filter)
     self.ins.bind((iface, type))
     self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2**30)
     self.outs = self.ins
     self.outs.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30)
     sa_ll = self.outs.getsockname()
     if sa_ll[3] in conf.l2types:
         self.LL = conf.l2types[sa_ll[3]]
     elif sa_ll[1] in conf.l3types:
         self.LL = conf.l3types[sa_ll[1]]
     else:
         warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using Ethernet" % (sa_ll[0],sa_ll[1],sa_ll[3]))
         self.LL = Ether
예제 #4
0
 def __init__(self,
              type=ETH_P_ALL,
              filter=None,
              promisc=None,
              iface=None,
              nofilter=0):
     self.type = type
     self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                              socket.htons(type))
     self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)
     flush_fd(self.ins)
     if iface:
         self.ins.bind((iface, type))
     if not nofilter:
         if conf.except_filter:
             if filter:
                 filter = "(%s) and not (%s)" % (filter, conf.except_filter)
             else:
                 filter = "not (%s)" % conf.except_filter
         if filter is not None:
             attach_filter(self.ins, filter)
     self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2**30)
     self.outs = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                               socket.htons(type))
     self.outs.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30)
     if promisc is None:
         promisc = conf.promisc
     self.promisc = promisc
     if self.promisc:
         if iface is None:
             self.iff = get_if_list()
         else:
             if iface.__class__ is list:
                 self.iff = iface
             else:
                 self.iff = [iface]
         for i in self.iff:
             set_promisc(self.ins, i)