当前位置: 首页>>代码示例>>Python>>正文


Python error.Scapy_Exception方法代码示例

本文整理汇总了Python中scapy.error.Scapy_Exception方法的典型用法代码示例。如果您正苦于以下问题:Python error.Scapy_Exception方法的具体用法?Python error.Scapy_Exception怎么用?Python error.Scapy_Exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scapy.error的用法示例。


在下文中一共展示了error.Scapy_Exception方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def __call__(cls, filename):
        """Creates a cls instance, use the `alternative` if that
        fails.

        """
        i = cls.__new__(cls, cls.__name__, cls.__bases__, cls.__dict__)
        filename, fdesc, magic = cls.open(filename)
        try:
            i.__init__(filename, fdesc, magic)
        except Scapy_Exception:
            if "alternative" in cls.__dict__:
                cls = cls.__dict__["alternative"]
                i = cls.__new__(cls, cls.__name__, cls.__bases__, cls.__dict__)
                try:
                    i.__init__(filename, fdesc, magic)
                except Scapy_Exception:
                    try:
                        i.f.seek(-4, 1)
                    except Exception:
                        pass
                    raise Scapy_Exception("Not a supported capture file")

        return i 
开发者ID:secdev,项目名称:scapy,代码行数:25,代码来源:utils.py

示例2: pre_dissect

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def pre_dissect(self, s):
        """
        Check that a valid DNS over TCP message can be decoded
        """
        if isinstance(self.underlayer, TCP):

            # Compute the length of the DNS packet
            if len(s) >= 2:
                dns_len = struct.unpack("!H", s[:2])[0]
            else:
                message = "Malformed DNS message: too small!"
                warning(message)
                raise Scapy_Exception(message)

            # Check if the length is valid
            if dns_len < 14 or len(s) < dns_len:
                message = "Malformed DNS message: invalid length!"
                warning(message)
                raise Scapy_Exception(message)

        return s


# https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4 
开发者ID:secdev,项目名称:scapy,代码行数:26,代码来源:dns.py

示例3: in6_cidr2mask

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def in6_cidr2mask(m):
    """
    Return the mask (bitstring) associated with provided length
    value. For instance if function is called on 48, return value is
    b'\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'.

    """
    if m > 128 or m < 0:
        raise Scapy_Exception("value provided to in6_cidr2mask outside [0, 128] domain (%d)" % m)  # noqa: E501

    t = []
    for i in range(0, 4):
        t.append(max(0, 2**32 - 2**(32 - min(32, m))))
        m -= 32

    return b"".join(struct.pack('!I', x) for x in t) 
开发者ID:secdev,项目名称:scapy,代码行数:18,代码来源:utils6.py

示例4: get_if_hwaddr

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def get_if_hwaddr(iff):
    addrfamily, mac = get_if_raw_hwaddr(iff)  # noqa: F405
    if addrfamily in [ARPHDR_ETHER, ARPHDR_LOOPBACK]:
        return str2mac(mac)
    else:
        raise Scapy_Exception("Unsupported address family (%i) for interface [%s]" % (addrfamily, iff))  # noqa: E501


# Next step is to import following architecture specific functions:
# def get_if_raw_hwaddr(iff)
# def get_if_raw_addr(iff):
# def get_if_list():
# def get_working_if():
# def attach_filter(s, filter, iface):
# def set_promisc(s,iff,val=1):
# def read_routes():
# def read_routes6():
# def get_if(iff,cmd):
# def get_if_index(iff): 
开发者ID:secdev,项目名称:scapy,代码行数:21,代码来源:__init__.py

示例5: open_pcap

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def open_pcap(iface, *args, **kargs):
        """open_pcap: Windows routine for creating a pcap from an interface.
        This function is also responsible for detecting monitor mode.
        """
        iface_pcap_name = pcapname(iface)
        if not isinstance(iface, NetworkInterface) and \
           iface_pcap_name is not None:
            iface = IFACES.dev_from_name(iface)
        if iface is None or iface.is_invalid():
            raise Scapy_Exception(
                "Interface is invalid (no pcap match found) !"
            )
        # Only check monitor mode when manually specified.
        # Checking/setting for monitor mode will slow down the process, and the
        # common is case is not to use monitor mode
        kw_monitor = kargs.get("monitor", None)
        if conf.use_npcap and kw_monitor is not None:
            monitored = iface.ismonitor()
            if kw_monitor is not monitored:
                # The monitor param is specified, and not matching the current
                # interface state
                iface.setmonitor(kw_monitor)
        return _orig_open_pcap(iface_pcap_name, *args, **kargs) 
开发者ID:secdev,项目名称:scapy,代码行数:25,代码来源:__init__.py

示例6: send

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def send(self, pkt):
        """Send a packet"""

        # Use the routing table to find the output interface
        iff = pkt.route()[0]
        if iff is None:
            iff = conf.iface

        # Assign the network interface to the BPF handle
        if self.assigned_interface != iff:
            try:
                fcntl.ioctl(self.outs, BIOCSETIF, struct.pack("16s16x", iff.encode()))  # noqa: E501
            except IOError:
                raise Scapy_Exception("BIOCSETIF failed on %s" % iff)
            self.assigned_interface = iff

        # Build the frame
        frame = raw(self.guessed_cls() / pkt)
        pkt.sent_time = time.time()

        # Send the frame
        L2bpfSocket.send(self, frame)


# Sockets manipulation functions 
开发者ID:secdev,项目名称:scapy,代码行数:27,代码来源:supersocket.py

示例7: cancel

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def cancel(handle):
        """Provided its handle, cancels the execution of a timeout."""

        handles = TimeoutScheduler._handles
        with TimeoutScheduler._mutex:
            if handle in handles:
                # Time complexity is O(n)
                handle._cb = None
                handles.remove(handle)
                heapq.heapify(handles)

                if len(handles) == 0:
                    # set the event to stop the wait - this kills the thread
                    TimeoutScheduler._event.set()
            else:
                raise Scapy_Exception("Handle not found") 
开发者ID:secdev,项目名称:scapy,代码行数:18,代码来源:isotp.py

示例8: addfield

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def addfield(self, pkt, s, val):
        val = self.i2m(pkt, val)
        data = []
        while val:
            if val > 127:
                data.append(val & 127)
                val //= 128
            else:
                data.append(val)
                lastoffset = len(data) - 1
                data = b"".join(chb(val | (0 if i == lastoffset else 128))
                                for i, val in enumerate(data))
                return s + data
            if len(data) > 3:
                raise Scapy_Exception("%s: malformed length field" %
                                      self.__class__.__name__)
        # If val is None / 0
        return s + b"\x00" 
开发者ID:secdev,项目名称:scapy,代码行数:20,代码来源:mqtt.py

示例9: make_reply

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def make_reply(self, req):
        if self.supported_responses is not None:
            for resp in self.supported_responses:
                if not isinstance(resp, ECUResponse):
                    raise Scapy_Exception("Unsupported type for response. "
                                          "Please use `ECUResponse` objects. ")

                if not resp.in_correct_session(self.ecu_state.current_session):
                    continue

                if not resp.has_security_access(
                        self.ecu_state.current_security_level):
                    continue

                if not resp.answers(req):
                    continue

                for r in resp.responses:
                    for layer in r.layers():
                        if hasattr(layer, "modifies_ecu_state"):
                            layer.modifies_ecu_state(r, self.ecu_state)

                return resp.responses

        return PacketList([self.basecls(b"\x7f" + bytes(req)[0:1] + b"\x10")]) 
开发者ID:secdev,项目名称:scapy,代码行数:27,代码来源:ecu.py

示例10: get_label

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def get_label(response,
                  positive_case="PR: PositiveResponse",
                  negative_case="NR: NegativeResponse"):
        if response is None:
            label = "Timeout"
        elif response.service == 0x7f:
            # FIXME: service is a protocol specific field
            label = negative_case
        else:
            if isinstance(positive_case, six.string_types):
                label = positive_case
            elif callable(positive_case):
                label = positive_case()
            else:
                raise Scapy_Exception("Unsupported Type for positive_case. "
                                      "Provide a string or a function.")
        return label 
开发者ID:secdev,项目名称:scapy,代码行数:19,代码来源:enumerator.py

示例11: sr1_file

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def sr1_file(test_params, test_filename, display_packet=False):
    """Read test message from given file, sends this message to server and parses response."""
    with open(test_filename, "rb") as file_handle:
        test_packet = file_handle.read()
    if display_packet:
        # print("Protocol: {}".format(proto_mapping(test_params.protocol)))
        try:
            if test_params.protocol in PROTOCOL_TESTERS:
                out_packet = PROTOCOL_TESTERS[test_params.protocol].request_parser(
                    test_packet
                )
            out_packet.show()
            print_verbose(test_params, 60 * "-")
        except (TypeError, struct.error, RuntimeError, ValueError, Scapy_Exception):
            pass
    test_result = None
    if test_params.protocol in [Protocol.SSDP]:
        test_result = ssdp_send_query(test_params, test_packet)
    elif test_params.protocol in protocols_using(UDP):
        test_result = udp_sr1(test_params, test_packet)
    elif test_params.protocol in protocols_using(TCP):
        test_result = tcp_sr1(test_params, test_packet)
    return test_result 
开发者ID:Samsung,项目名称:cotopaxi,代码行数:25,代码来源:cotopaxi_tester.py

示例12: make_route

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def make_route(self, host=None, net=None, gw=None, dev=None):
        if host is not None:
            thenet,msk = host,32
        elif net is not None:
            thenet,msk = net.split("/")
            msk = int(msk)
        else:
            raise Scapy_Exception("make_route: Incorrect parameters. You should specify a host or a net")
        if gw is None:
            gw="0.0.0.0"
        if dev is None:
            if gw:
                nhop = gw
            else:
                nhop = thenet
            dev,ifaddr,x = self.route(nhop)
        else:
            ifaddr = get_if_addr(dev)
        return (atol(thenet), itom(msk), gw, dev, ifaddr) 
开发者ID:entynetproject,项目名称:arissploit,代码行数:21,代码来源:route.py

示例13: send

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def send(self, x):
                raise Scapy_Exception("Can't send anything with L2pcapListenSocket") 
开发者ID:medbenali,项目名称:CyberScan,代码行数:4,代码来源:pcapdnet.py

示例14: get_if_raw_hwaddr

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def get_if_raw_hwaddr(iff):
            if iff == scapy.arch.LOOPBACK_NAME:
                return (772, '\x00'*6)
            try:
                l = dnet.intf().get(iff)
                l = l["link_addr"]
            except:
                raise Scapy_Exception("Error in attempting to get hw address for interface [%s]" % iff)
            return l.type,l.data 
开发者ID:medbenali,项目名称:CyberScan,代码行数:11,代码来源:pcapdnet.py

示例15: send

# 需要导入模块: from scapy import error [as 别名]
# 或者: from scapy.error import Scapy_Exception [as 别名]
def send(self, x):
        raise Scapy_Exception("Can't send anything with L2ListenSocket") 
开发者ID:theralfbrown,项目名称:smod-1,代码行数:4,代码来源:linux.py


注:本文中的scapy.error.Scapy_Exception方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。