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


Python inet6.IPv6方法代码示例

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


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

示例1: recv_raw

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def recv_raw(self, x=MTU):
        try:
            data, address = self.ins.recvfrom(x)
        except io.BlockingIOError:
            return None, None, None
        from scapy.layers.inet import IP
        from scapy.layers.inet6 import IPv6
        if self.ipv6:
            # AF_INET6 does not return the IPv6 header. Let's build it
            # (host, port, flowinfo, scopeid)
            host, _, flowinfo, _ = address
            header = raw(IPv6(src=host,
                              dst=self.host_ip6,
                              fl=flowinfo,
                              nh=self.proto,  # fixed for AF_INET6
                              plen=len(data)))
            return IPv6, header + data, time.time()
        else:
            return IP, data, time.time() 
开发者ID:secdev,项目名称:scapy,代码行数:21,代码来源:native.py

示例2: guess_payload_class

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def guess_payload_class(self, payload):
        if len(payload) >= 1:
            if not self.s:
                return MPLS
            ip_version = (orb(payload[0]) >> 4) & 0xF
            if ip_version == 4:
                return IP
            elif ip_version == 5:
                return BIER
            elif ip_version == 6:
                return IPv6
            else:
                if orb(payload[0]) == 0 and orb(payload[1]) == 0:
                    return EoMCW
                else:
                    return Ether
        return Padding 
开发者ID:secdev,项目名称:scapy,代码行数:19,代码来源:mpls.py

示例3: guess_payload_class

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def guess_payload_class(self, payload):
        # Snooped from Wireshark
        # https://github.com/boundary/wireshark/blob/07eade8124fd1d5386161591b52e177ee6ea849f/epan/dissectors/packet-gtp.c#L8195  # noqa: E501
        if self.E == 1:
            if self.next_ex == 0x85:
                return GTPPDUSessionContainer
            return GTPHeader.guess_payload_class(self, payload)

        if self.gtp_type == 255:
            sub_proto = orb(payload[0])
            if sub_proto >= 0x45 and sub_proto <= 0x4e:
                return IP
            elif (sub_proto & 0xf0) == 0x60:
                return IPv6
            else:
                return PPP
        return GTPHeader.guess_payload_class(self, payload)


# Some gtp_types have to be associated with a certain type of header 
开发者ID:secdev,项目名称:scapy,代码行数:22,代码来源:gtp.py

示例4: recv_from_tuntcp

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def recv_from_tuntcp(socket, packet):
    plen, type = unpack("!HH", packet[0:4])
    log.debug("Len: %d Type %d" % (plen, type))
    # Assume that we got the whole packet...
    # In the future we should check - and wait for more if not complete.
    if type == TYPE_HANDSHAKE_MAC_GET:
        data = struct.pack("!HH", 8 + 4, TYPE_HANDSHAKE_MAC_SET) + get_next_mac()
        socket.send(data)
    elif type == TYPE_RAW_IPV6:
        ip = IPv6(packet[4:])
        dst = ipaddress.ip_address(ip.dst)
        # Not matching prefix... Send to all tuntcp except "socket" to get things out to other nodes.
        if dst.packed[0:4] != prefix[0:4]:
            log.debug("Not matching prefix - send back to all. %d" % len(tuntcp))
            ip.show()
            send_to_tuntcp(socket, packet[4:])
        else:
            recv_from_tun(packet[4:])

# Only for OS-X for now.
# Should be easy to adapt for linux also. 
开发者ID:joakimeriksson,项目名称:ai-smarthome,代码行数:23,代码来源:nat64.py

示例5: _write_header

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def _write_header(self, pkt):
        if self.linktype is None:
            try:
                self.linktype = conf.l2types[pkt.__class__]
                # Import here to prevent import loops
                from scapy.layers.inet import IP
                from scapy.layers.inet6 import IPv6
                if OPENBSD and isinstance(pkt, (IP, IPv6)):
                    self.linktype = 14  # DLT_RAW
            except KeyError:
                warning("PcapWriter: unknown LL type for %s. Using type 1 (Ethernet)", pkt.__class__.__name__)  # noqa: E501
                self.linktype = DLT_EN10MB
        RawPcapWriter._write_header(self, pkt) 
开发者ID:secdev,项目名称:scapy,代码行数:15,代码来源:utils.py

示例6: sixlowpan_fragment

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def sixlowpan_fragment(packet, datagram_tag=1):
    """Split a packet into different links to transmit as 6lowpan packets.
    Usage example::

      >>> ipv6 = ..... (very big packet)
      >>> pkts = sixlowpan_fragment(ipv6, datagram_tag=0x17)
      >>> send = [Dot15d4()/Dot15d4Data()/x for x in pkts]
      >>> wireshark(send)
    """
    if not packet.haslayer(IPv6):
        raise Exception("SixLoWPAN only fragments IPv6 packets !")

    str_packet = raw(packet[IPv6])

    if len(str_packet) <= MAX_SIZE:
        return [packet]

    def chunks(li, n):
        return [li[i:i + n] for i in range(0, len(li), n)]

    new_packet = chunks(str_packet, MAX_SIZE)

    new_packet[0] = LoWPANFragmentationFirst(datagramTag=datagram_tag, datagramSize=len(str_packet)) / new_packet[0]  # noqa: E501
    i = 1
    while i < len(new_packet):
        new_packet[i] = LoWPANFragmentationSubsequent(datagramTag=datagram_tag, datagramSize=len(str_packet), datagramOffset=MAX_SIZE // 8 * i) / new_packet[i]  # noqa: E501
        i += 1

    return new_packet 
开发者ID:secdev,项目名称:scapy,代码行数:31,代码来源:sixlowpan.py

示例7: post_build

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def post_build(self, p, pay):
        if self.chksum is None:
            if isinstance(self.underlayer, IP):
                ck = in4_chksum(112, self.underlayer, p)
            elif isinstance(self.underlayer, IPv6):
                ck = in6_chksum(112, self.underlayer, p)
            else:
                warning("No IP(v6) layer to compute checksum on VRRP. Leaving null")  # noqa: E501
                ck = 0
            p = p[:6] + chb(ck >> 8) + chb(ck & 0xff) + p[8:]
        return p 
开发者ID:secdev,项目名称:scapy,代码行数:13,代码来源:vrrp.py

示例8: dispatch_hook

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def dispatch_hook(cls, _pkt=None, *args, **kargs):
        if _pkt and len(_pkt) >= 16:
            ver_n_type = orb(_pkt[0])
            if ver_n_type < 48 or ver_n_type > 57:  # Version != 3
                return VRRP
        return VRRPv3


# IPv6 is supported only on VRRPv3
# Warning: those layers need to be un-binded in the CARP contrib module.
# If you add/remove any, remember to also edit the one in CARP.py 
开发者ID:secdev,项目名称:scapy,代码行数:13,代码来源:vrrp.py

示例9: nonblock_recv

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def nonblock_recv(self, x=MTU):
        return self.recv()

    # https://docs.microsoft.com/en-us/windows/desktop/winsock/tcp-ip-raw-sockets-2  # noqa: E501
    # - For IPv4 (address family of AF_INET), an application receives the IP
    # header at the front of each received datagram regardless of the
    # IP_HDRINCL socket option.
    # - For IPv6 (address family of AF_INET6), an application receives
    # everything after the last IPv6 header in each received datagram
    # regardless of the IPV6_HDRINCL socket option. The application does
    # not receive any IPv6 headers using a raw socket. 
开发者ID:secdev,项目名称:scapy,代码行数:13,代码来源:native.py

示例10: receive

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def receive(self):
        log.debug("UDP: socket receive:", self)
        data, addr = self.sock.recvfrom(self.maxreceive)
        if not data:
            sock_remove(self.sock)
            return None
        ipv6 = IPv6(IPv6(src = self.dst, dst = self.src)/UDP(sport=self.dport, dport=self.sport)/raw(data))
        send_to_tun(ipv6)
        return data 
开发者ID:joakimeriksson,项目名称:ai-smarthome,代码行数:11,代码来源:nat64.py

示例11: update_tcp_state_totun

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def update_tcp_state_totun(self, data):
        ipv6 = IPv6(src = self.dst, dst = self.src)/TCP(sport=self.dport, dport=self.sport, flags="PA") / raw(data)
        # Update with the current seq and ack.
        ipv6.seq = self.seq
        ipv6.ack = self.ack
        return ipv6

    # receive packet and send to tun. 
开发者ID:joakimeriksson,项目名称:ai-smarthome,代码行数:10,代码来源:nat64.py

示例12: do_build

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def do_build(self):
        if not isinstance(self.payload, IPv6):
            return Packet.do_build(self)
        ipv6 = self.payload

        self._reserved = 0x03

        # NEW COMPRESSION TECHNIQUE!
        # a ) Compression Techniques

        # 1. Set Traffic Class
        if self.tf == 0x0:
            self.tc_ecn = ipv6.tc >> 6
            self.tc_dscp = ipv6.tc & 0x3F
            self.flowlabel = ipv6.fl
        elif self.tf == 0x1:
            self.tc_ecn = ipv6.tc >> 6
            self.flowlabel = ipv6.fl
        elif self.tf == 0x2:
            self.tc_ecn = ipv6.tc >> 6
            self.tc_dscp = ipv6.tc & 0x3F
        else:  # self.tf == 0x3:
            pass  # no field is set

        # 2. Next Header
        if self.nh == 0x0:
            self.nh = 0  # ipv6.nh
        elif self.nh == 0x1:
            self.nh = 0  # disable compression
            # The Next Header field is compressed and the next header is encoded using LOWPAN_NHC, which is discussed in Section 4.1.  # noqa: E501
            warning('Next header compression is not implemented yet ! Will be ignored')  # noqa: E501

        # 3. HLim
        if self.hlim == 0x0:
            self._hopLimit = ipv6.hlim
        else:  # if hlim is 1, 2 or 3, there are nothing to do!
            pass

        # 4. Context (which context to use...)
        if self.cid == 0x0:
            pass
        else:
            # TODO: Context Unimplemented yet in my class
            self._contextIdentifierExtension = 0

        # 5. Compress Source Addr
        self.compressSourceAddr(ipv6)
        self.compressDestinyAddr(ipv6)

        return Packet.do_build(self) 
开发者ID:secdev,项目名称:scapy,代码行数:52,代码来源:sixlowpan.py

示例13: handle_tcp_state_tosock

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def handle_tcp_state_tosock(self, ip):
        global tun, input
        log.debug("=== NAT64 TCP sock-send: %d %s."%(ip.flags, self.sock))
        if self.sock is None:
            log.warning("Socket already closed.")
            return
        if ip.flags.S:
            # Use Window size to control max segment?
            self.sock.setsockopt(socket.SOL_TCP, socket.TCP_MAXSEG, 1000)
            log.debug("Maxseg: %d" % self.sock.getsockopt(socket.SOL_TCP, socket.TCP_MAXSEG))
            self.ack = ip.seq + 1
            # We are established...
            self.state = TCP_ESTABLISHED
            self.window = ip[TCP].window
            # Get the MSS of the options
            for k, v in ip[TCP].options:
                if k == 'MSS':
                    self.mss = v
            log.debug("TCP State: %s SYN received." % self)
            ipv6 = IPv6(src=ip.dst, dst=ip.src)/TCP(sport=ip.dport, dport=ip.sport, flags="SA", seq=self.seq, ack=self.ack)
            ipv6.show()
            send_to_tun(bytes(IPv6(ipv6)))
        #    sock.send(ip.load)
        elif ip.flags.FA or ip.flags.F:
            self.state = TCP_FIN_CLOSE_WAIT
            self.ack = ip.seq + 1
            self.timeout = time.time()
            log.debug("TCP: FIN received - sending FIN. %s" % self)
            ipv6 = IPv6(src=ip.dst, dst=ip.src)/TCP(sport=ip.dport, dport=ip.sport, flags="FA", seq=self.seq, ack=self.ack)
            ipv6.show()
            send_to_tun(bytes(IPv6(ipv6)))
            # Clean out this socket?
        elif ip.flags.A or ip.flags.AP:
            if self.state == TCP_ESTABLISHED:
                if not hasattr(ip,'load'):
                    log.debug("ESTABLISHED or ACK from other side. seq: %d  ack: %d" % (ip.seq, ip.ack))
                    self.seq = ip.ack
                else:
                    # ACK immediately - we assume that we get data from other side soon...
                    log.debug("TCP: received %d seq: %d  ack%d ." % (len(ip.load), ip.seq, ip.ack))
                    self.ack = ip.seq + len(ip.load)
                    # We should also handle the sanity checks for the ACK
                    self.seq = ip.ack
                    ipv6 = IPv6(src=ip.dst, dst=ip.src)/TCP(sport=ip.dport, dport=ip.sport, flags="A", seq=self.seq, ack=self.ack)
                    ipv6 = IPv6(ipv6)
                    ipv6.show()
                    send_to_tun(bytes(ipv6))
            add_socket(self.sock)
        if hasattr(ip, 'load'):
            self.sock.send(ip.load) 
开发者ID:joakimeriksson,项目名称:ai-smarthome,代码行数:52,代码来源:nat64.py

示例14: nat64_send

# 需要导入模块: from scapy.layers import inet6 [as 别名]
# 或者: from scapy.layers.inet6 import IPv6 [as 别名]
def nat64_send(ip):
    global input, udp_port, tcp_port
    # NAT64 translation
    dst = ipaddress.ip_address(ip.dst)
    if dst.packed[0:4] == prefix[0:4]:
        ip4dst = ipaddress.ip_address(dst.packed[-4:])
        log.debug("NAT64 dst: %s %d." % (ip4dst, ip.nh))
        key = genkey(ip.nh, ip.src, ip4dst, ip.sport, ip.dport)
        if ip.nh == PROTO_UDP:
            if DNS in ip:
                log.debug("DNS name:", ip[DNS].opcode)
                if ip[DNS].opcode == 0 and ip[DNS].qdcount > 0:
                    addr = socket.gethostbyname(ip[DNSQR].qname)
                    dns64addr = ipaddress.ip_address(prefix[0:16-4] +
                                                     ipaddress.ip_address(addr).packed)
                    log.debug("%s => %s  %s" % (ip[DNSQR].name , addr, str(dns64addr)))
                    name = ip[DNSQR].qname
                    ipaddr = dns64addr
                    resp = IPv6(dst=ip.src, src=ip.dst)/UDP(dport=ip[UDP].sport, sport=53)/DNS(id=ip[DNS].id, qr=1, ancount=1)/DNSRR(type='AAAA', rrname=name,rdata=ipaddr, ttl=3600)
                    reps = IPv6(resp)
                    resp.show()
                    log.debug(repr(resp))
                    send_to_tun(resp)
                    return 0
            if key not in adrmap:
                udp = UDP64State(ip.src, ip.dst, ip.sport, ip.dport)
                adrmap[key] = udp.sock
                sockmap[udp.sock] = udp
                log.debug("Opened sock: %s" % udp.sock)
                add_socket(udp.sock)
                sock = udp.sock
            else:
                sock = adrmap[key]
            sock.send(bytes(ip[UDP]))
        elif ip.nh == PROTO_TCP:
            if key not in adrmap:
                tcp = TCP64State(ip.src, ip.dst, ip.sport, ip.dport)
                adrmap[key] = tcp.sock
                sockmap[tcp.sock] = tcp
                add_socket(tcp.sock)
                sock = tcp.sock
            else:
                sock = adrmap[key]
            tcp = sockmap[sock]
            tcp.handle_tcp_state_tosock(ip)

# Tun is reception from local machine - not from native or NBR. 
开发者ID:joakimeriksson,项目名称:ai-smarthome,代码行数:49,代码来源:nat64.py


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