示例#1
0
 def sr1(self, *args, **kargs):
     from scapy import sendrecv
     a, b = sendrecv.sndrcv(self, *args, **kargs)
     if len(a) > 0:
         return a[0][1]
     else:
         return None
 def sr1(self, *args, **kargs):
     from scapy import sendrecv
     a, b = sendrecv.sndrcv(self, *args, **kargs)
     if len(a) > 0:
         return a[0][1]
     else:
         return None
示例#3
0
def srradio(pkts, inter=0.1, radio=None, ch=None, env=None, *args, **kargs):
    """send and receive using a Gnuradio socket"""
    sr_packets = []
    if radio is not None:
        switch_radio_protocol(radio, ch=ch, env=env, mode='rf')
    s = GnuradioSocket()
    for pkt in pkts:
        # recently_sent_pkt = str(pkt.payload)
        # print('Packet Payload: ', str(pkt.payload))
        # for layer in get_packet_layers(pkt):
        #         print('\n-----------------------------')
        #         print('Layer: ', layer.name)
        #         print('Layer str: ', str(layer))
        # s.send(pkt.payload)
        # start = time.time()
        # rv = sendrecv.sniff(opened_socket=s, timeout=5)
        # for r_pkt in rv:
        #     print('Received Packet: ', str(r_pkt))
        #     for layer in get_packet_layers(r_pkt):
        #         print('\n-----------------------------')
        #         print('Layer: ', layer.name)
        #         print('Layer str: ', str(layer))
        #     print('Received Packet Payload: ', str(r_pkt.payload))
        #     if r_pkt != None and str(r_pkt) != recently_sent_pkt:
        #         sr_packets.append(r_pkt)
        a, b = sendrecv.sndrcv(s, pkts, inter=inter, verbose=True, store_unanswered=True, *args, **kargs)
    print(a)
    print(b)
    s.close()
    conf.gr_process.kill()
    #return a, b
    return sr_packets
示例#4
0
def srbt(bt_address, pkts, inter=0.1, *args, **kargs):
    """send and receive using a bluetooth socket"""
    if "port" in kargs:
        s = conf.BTsocket(bt_address=bt_address, port=kargs.pop("port"))
    else:
        s = conf.BTsocket(bt_address=bt_address)
    a, b = sndrcv(s, pkts, inter=inter, *args, **kargs)
    s.close()
    return a, b
示例#5
0
文件: bluetooth.py 项目: 6WIND/scapy
def srbt(bt_address, pkts, inter=0.1, *args, **kargs):
    """send and receive using a bluetooth socket"""
    if "port" in kargs.keys():
        s = conf.BTsocket(bt_address=bt_address, port=kargs.pop("port"))
    else:
        s = conf.BTsocket(bt_address=bt_address)
    a,b = sndrcv(s,pkts,inter=inter,*args,**kargs)
    s.close()
    return a,b
示例#6
0
 def sr1(self, *args, **kargs):
     # type: (Any, Any) -> Optional[Packet]
     from scapy import sendrecv
     ans = sendrecv.sndrcv(self, *args, **kargs)[0]  # type: SndRcvList
     if len(ans) > 0:
         pkt = ans[0][1]  # type: Packet
         return pkt
     else:
         return None
示例#7
0
 def sr1(self, *args, **kargs):
     # type: (Any, Any) -> Optional[Packet]
     from scapy import sendrecv
     a, b = sendrecv.sndrcv(
         self, *args, **kargs)  # type: PacketList, PacketList  # noqa: E501
     if len(a) > 0:
         pkt = a[0][1]  # type: Packet
         return pkt
     else:
         return None
示例#8
0
文件: can.py 项目: amralk/scapy
def srcan(pkt,
          iface=None,
          receive_own_messages=False,
          filter=None,
          nofilter=0,
          *args,
          **kargs):
    if not "timeout" in kargs:
        kargs["timeout"] = -1
    s = conf.CANSocket(iface, receive_own_messages, filter, nofilter)
    a, b = sndrcv(s, pkt, *args, **kargs)
    s.close()
    return a, b
示例#9
0
    def get_gw_mac_address(self, iface):

        for i in range(5):
            arp_req_ip_dst = self.gateways[iface]

            source_hw_addr = get_if_hwaddr(iface)

            arp_req = Ether(dst="ff:ff:ff:ff:ff:ff", src=source_hw_addr) / \
                      ARP(pdst=arp_req_ip_dst, psrc=get_if_addr(iface), hwsrc=source_hw_addr)

            ans, unans = sndrcv(self.sockets[iface], arp_req, timeout=1, verbose=0)

            if len(ans) < 1:
                continue

            return ans[0][1].src

        raise ConnectionError("ARP Resolution Failed for %s (%s)" % (self.gateways[iface], iface))
示例#10
0
 def sr(self, *args, **kargs):
     # type: (Any, Any) -> Tuple[SndRcvList, PacketList]
     from scapy import sendrecv
     ans, unans = sendrecv.sndrcv(
         self, *args, **kargs)  # type: SndRcvList, PacketList  # noqa: E501
     return ans, unans
示例#11
0
def srradio(pkts, inter=0.1, *args, **kargs):
    """send and receive using a Gnuradio socket"""
    s = GnuradioSocket()
    a, b = sendrecv.sndrcv(s, pkts, inter=inter, *args, **kargs)
    s.close()
    return a, b
 def sr(self, *args, **kargs):
     from scapy import sendrecv
     return sendrecv.sndrcv(self, *args, **kargs)
示例#13
0
文件: isotp.py 项目: plorinquer/scapy
 def sr(self, *args, **kargs):
     return sndrcv(self, *args, **kargs)
示例#14
0
文件: isotp.py 项目: plorinquer/scapy
 def sr1(self, *args, **kargs):
     data = sndrcv(self, *args, **kargs)
     if data:
         return data[0][0][1]
def srbt(peer, pkts, inter=0.1, *args, **kargs):
    """send and receive using a bluetooth socket"""
    s = conf.BTsocket(peer=peer)
    a, b = sndrcv(s, pkts, inter=inter, *args, **kargs)
    s.close()
    return a, b
示例#16
0
    def check_interface(self, interface):
        try:
            if interface not in self.gateways:
                self.log.debug("No gateway fetched for %s" % interface)
                return False

            if hasattr(self.ipdb.interfaces[interface], "carrier"
                       ) and self.ipdb.interfaces[interface].carrier == 0:
                return False

            count = self.configuration["interfaces"][interface].get(
                "count", DEFAULT_COUNT)
            max_lost = self.configuration["interfaces"][interface].get(
                "max_lost", DEFAULT_MAX_LOST)
            max_delay = self.configuration["interfaces"][interface].get(
                "max_delay", DEFAULT_MAX_DELAY)

            delays = []
            id = random.randint(1, 65535)

            if_addr = get_if_addr(interface)

            if self.use_l2_packet(interface):

                try:
                    mac_address_gw = self.get_gw_mac_address(interface)
                except ConnectionError as ex:
                    self.log.error(ex.args[0])
                    return False

                if_hw_addr = get_if_hwaddr(interface)
                header = Ether(dst=mac_address_gw, src=if_hw_addr)

            else:
                # if using an L3 socket for this interface ->
                # add scapy route to route L3 traffic on the probed interface
                # the route will not be added to the kernel routing table
                scapyconf.route.add(net='%s/32' % self.configuration["host"],
                                    dev=interface)
                header = None

            for i in range(count):

                if self.exited.is_set():
                    return

                if header:
                    packet = header / \
                             IP(src=if_addr, dst=self.configuration["host"]) / \
                             ICMP(id=id, seq=i + 1)
                else:
                    packet = IP(src=if_addr, dst=self.configuration["host"]) / \
                             ICMP(id=id, seq=i + 1)

                ans, unans = sndrcv(self.sockets[interface],
                                    packet,
                                    timeout=1,
                                    verbose=0)

                # self.log.debug("Ping sent")
                if len(ans) > 0:
                    if ans[0][1][ICMP].type == 0 and ans[0][1][ICMP].id == id:
                        rx = ans[0][1]
                        tx = ans[0][0]
                        delta = rx.time - tx.sent_time
                        delays.append(delta)
                    else:
                        self.log.debug(
                            "[%s] Missed ping seq=%s - ICMP Recv Type: %s (must be 0) - Id: %s (must be %s) "
                            % (interface, i + 1, ans[0][1][ICMP].type,
                               ans[0][1][ICMP].id, id))
                else:
                    self.log.debug("[%s] Missed ping id=%s seq=%s  - Timeout" %
                                   (interface, id, i + 1))

                self.exited.wait(timeout=DEFAULT_DELAY / 1000)

            # if using an L3 socket for this interface -> remove scapy route
            if header is None:
                scapyconf.route.delt(net='%s/32' % self.configuration["host"],
                                     dev=interface)

            if len(delays) == 0:
                return False

            ok_count = len(delays)
            delay_avg = sum(delays) / ok_count
            is_ok = (count - ok_count) <= max_lost and (delay_avg *
                                                        1000) < max_delay
            self.log.debug(
                "[%s %s] Ping %s via %s result - lost: %s/%s, delay: %0.0f ms"
                % (interface, "OK" if is_ok else "FAIL",
                   self.configuration["host"], self.gateways[interface],
                   (count - ok_count), count, delay_avg * 1000))
            return is_ok

        except PermissionError as pe:
            raise pe

        except Exception as ex:
            self.log.exception("check_interface error: ")
            return False
示例#17
0
 def sr(self, *args, **kargs):
     from scapy import sendrecv
     return sendrecv.sndrcv(self, *args, **kargs)
示例#18
0
 def sr(self, *args, **kargs):
     return sndrcv(self, *args, **kargs)
示例#19
0
 def sr1(self, *args, **kargs):
     a, b = sndrcv(self, *args, **kargs)
     if len(a) > 0:
         return a[0][1]
     else:
         return None
示例#20
0
def srradio(pkts, inter=0.1, *args, **kargs):
    """send and receive using a Gnuradio socket"""
    s = GnuradioSocket()
    a, b = sendrecv.sndrcv(s, pkts, inter=inter, *args, **kargs)
    s.close()
    return a, b
示例#21
0
文件: can.py 项目: zbx91/sniffer
 def sr(self, *args, **kargs):
     return sendrecv.sndrcv(self, *args, **kargs)
示例#22
0
conf.use_pcap = True

while True:
    iface = "ppp0"

    s = L3PacketSocket(iface=iface)

    id = random.randint(1, 1 << 15)

    ppp0_ip = get_if_addr(iface)
    conf.route.add(net='8.8.8.8/32', dev=iface)

    for i in range(5):
        packet = IP(src=ppp0_ip, dst="8.8.8.8") / ICMP(
            id=id, seq=random.randint(1, 1 << 15))
        ans, _ = sndrcv(s, packet, timeout=10, verbose=0)

        # self.log.debug("Ping sent")
        rx = False
        if len(ans) > 0:
            if ans[0][1][ICMP].type == 0 and ans[0][1][ICMP].id == id:
                # rx = ans[0][1]
                # tx = ans[0][0]
                # delta = rx.time - tx.sent_time
                # rx = True
                print("ok")
            else:
                print("ICMP")
        else:
            print("Timeout")
示例#23
0
文件: bluetooth.py 项目: mcpat/scapy
def srbt(peer, pkts, inter=0.1, *args, **kargs):
    """send and receive using a bluetooth socket"""
    s = conf.BTsocket(peer=peer)
    a,b = sndrcv(s,pkts,inter=inter,*args,**kargs)
    s.close()
    return a,b
示例#24
0
文件: isotp.py 项目: wukun0451/scapy
 def sr1(self, *args, **kargs):
     data = sndrcv(self, *args, **kargs)
     if data:
         return data[0][0][1]