當前位置: 首頁>>代碼示例>>Python>>正文


Python all.IPv6方法代碼示例

本文整理匯總了Python中scapy.all.IPv6方法的典型用法代碼示例。如果您正苦於以下問題:Python all.IPv6方法的具體用法?Python all.IPv6怎麽用?Python all.IPv6使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scapy.all的用法示例。


在下文中一共展示了all.IPv6方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: callback

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def callback(self, packet):
        flags = packet.sprintf("%TCP.flags%")
        proto = IP
        if IPv6 in packet:
            proto = IPv6
        if flags == "A" and not self.ignore_packet(packet, proto):
            src_mac = packet[Ether].src
            dst_mac = packet[Ether].dst
            src_ip = packet[proto].src
            dst_ip = packet[proto].dst
            src_port = packet[TCP].sport
            dst_port = packet[TCP].dport
            seq = packet[TCP].seq
            ack = packet[TCP].ack
            if self.verbose:
                print("RST from %s:%s (%s) --> %s:%s (%s) w/ %s" % (src_ip, src_port, src_mac, dst_ip, dst_port, dst_mac, ack))
            if self.noisy:
                self.send(self.build_packet(src_mac, dst_mac, src_ip, dst_ip, src_port, dst_port, seq, proto))
            self.send(self.build_packet(dst_mac, src_mac, dst_ip, src_ip, dst_port, src_port, ack, proto)) 
開發者ID:ecthros,項目名稱:pina-colada,代碼行數:21,代碼來源:tcpkiller.py

示例2: visit_packet

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def visit_packet(self, time, packet):
        if (IP not in packet and IPv6 not in packet) or TCP not in packet:
            return

        iph = packet[IP] if IP in packet else packet[IPv6]
        tcph = packet[TCP]

        if iph.src == self._rcv_ip:
            return

        port = tcph.sport
        if port not in self._packet_size:
            return

        # TODO(arjunroy) IPv4 = total len, IPv6 = payload len. Is it important?
        packet_len = packet.len if IP in packet else packet.plen
        sizes = self._packet_size[port]
        if packet_len in sizes:
            sizes[packet_len] += 1
        else:
            sizes[packet_len] = 1 
開發者ID:google,項目名稱:transperf,代碼行數:23,代碼來源:metric.py

示例3: send_dhcp_advertise

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def send_dhcp_advertise(p, basep, target):
    global ipv6noaddrc
    resp = Ether(dst=basep.src)/IPv6(src=config.selfaddr, dst=basep[IPv6].src)/UDP(sport=547, dport=546) #base packet
    resp /= DHCP6_Advertise(trid=p.trid)
    #resp /= DHCP6OptPref(prefval = 255)
    resp /= DHCP6OptClientId(duid=p[DHCP6OptClientId].duid)
    resp /= DHCP6OptServerId(duid=config.selfduid)
    resp /= DHCP6OptDNSServers(dnsservers=[config.selfaddr])
    if config.localdomain:
        resp /= DHCP6OptDNSDomains(dnsdomains=[config.localdomain])
    if target.ipv4 != '':
        addr = config.ipv6prefix + target.ipv4.replace('.', ':')
    else:
        addr = config.ipv6prefix + '%d:%d' % (config.ipv6noaddr, config.ipv6noaddrc)
        config.ipv6noaddrc += 1
    opt = DHCP6OptIAAddress(preflft=300, validlft=300, addr=addr)
    resp /= DHCP6OptIA_NA(ianaopts=[opt], T1=200, T2=250, iaid=p[DHCP6OptIA_NA].iaid)
    sendp(resp, iface=config.default_if, verbose=False) 
開發者ID:fox-it,項目名稱:mitm6,代碼行數:20,代碼來源:mitm6.py

示例4: send_dhcp_reply

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def send_dhcp_reply(p, basep):
    resp = Ether(dst=basep.src)/IPv6(src=config.selfaddr, dst=basep[IPv6].src)/UDP(sport=547, dport=546) #base packet
    resp /= DHCP6_Reply(trid=p.trid)
    #resp /= DHCP6OptPref(prefval = 255)
    resp /= DHCP6OptClientId(duid=p[DHCP6OptClientId].duid)
    resp /= DHCP6OptServerId(duid=config.selfduid)
    resp /= DHCP6OptDNSServers(dnsservers=[config.selfaddr])
    if config.localdomain:
        resp /= DHCP6OptDNSDomains(dnsdomains=[config.localdomain])
    try:
        opt = p[DHCP6OptIAAddress]
        resp /= DHCP6OptIA_NA(ianaopts=[opt], T1=200, T2=250, iaid=p[DHCP6OptIA_NA].iaid)
        sendp(resp, iface=config.default_if, verbose=False)
    except IndexError:
        # Some hosts don't send back this layer for some reason, ignore those
        if config.debug or config.verbose:
            print('Ignoring DHCPv6 packet from %s: Missing DHCP6OptIAAddress layer' % basep.src) 
開發者ID:fox-it,項目名稱:mitm6,代碼行數:19,代碼來源:mitm6.py

示例5: parsepacket

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def parsepacket(p):
    if DHCP6_Solicit in p:
        target = get_target(p)
        if should_spoof_dhcpv6(target.host):
            send_dhcp_advertise(p[DHCP6_Solicit], p, target)
    if DHCP6_Request in p:
        target = get_target(p)
        if p[DHCP6OptServerId].duid == config.selfduid and should_spoof_dhcpv6(target.host):
            send_dhcp_reply(p[DHCP6_Request], p)
            print('IPv6 address %s is now assigned to %s' % (p[DHCP6OptIA_NA].ianaopts[0].addr, pcdict[p.src]))
    if DHCP6_Renew in p:
        target = get_target(p)
        if p[DHCP6OptServerId].duid == config.selfduid and should_spoof_dhcpv6(target.host):
            send_dhcp_reply(p[DHCP6_Renew],p)
            print('Renew reply sent to %s' % p[DHCP6OptIA_NA].ianaopts[0].addr)
    if ARP in p:
        arpp = p[ARP]
        if arpp.op is 2:
            #Arp is-at package, update internal arp table
            arptable[arpp.hwsrc] = arpp.psrc
    if DNS in p:
        if p.dst == config.selfmac:
            send_dns_reply(p) 
開發者ID:fox-it,項目名稱:mitm6,代碼行數:25,代碼來源:mitm6.py

示例6: build_packet

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def build_packet(self, src_mac, dst_mac, src_ip, dst_ip, src_port, dst_port, seq, proto):
        eth = Ether(src=src_mac, dst=dst_mac, type=0x800)
        if proto == IP:
            ip = IP(src=src_ip, dst=dst_ip)
        elif proto == IPv6:
            ip = IPv6(src=src_ip, dst=dst_ip)
        else:
            return str(eth) #if unknown L2 protocol, send back dud ether packet
        tcp = TCP(sport=src_port, dport=dst_port, seq=seq, flags="R")
        return str(eth/ip/tcp) 
開發者ID:ecthros,項目名稱:pina-colada,代碼行數:12,代碼來源:tcpkiller.py

示例7: get_dhcpv6_server_duid

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def get_dhcpv6_server_duid():
    if dhcpv6_server_duid is None:
        print(Base.c_info + 'Wait for receive DHCPv6 server DUID...')
        tm.add_task(recv_dhcpv6_reply)
        sleep(3)
        send_dhcpv6_solicit()
        sleep(10)

        count_solicit_reqeusts = 0
        while count_solicit_reqeusts < 2:
            if dhcpv6_server_duid is None:
                send_dhcpv6_solicit()
                count_solicit_reqeusts += 1
                sleep(5)
            else:
                break

        if dhcpv6_server_duid is None:
            print(Base.c_error + 'Can not get DHCPv6 server DUID!')
            return False
        else:
            print(Base.c_success + 'DHCPv6 server MAC:       ' + str(dhcpv6_server_mac))
            print(Base.c_success + 'DHCPv6 server IPv6 link: ' + str(dhcpv6_server_ipv6_link))
            print(Base.c_success + 'DHCPv6 server DUID:      ' + str(dhcpv6_server_duid).encode('hex'))
            return True
    else:
        return True 
開發者ID:raw-packet,項目名稱:raw-packet,代碼行數:29,代碼來源:dnsmasploit.py

示例8: dhcpv6_callback

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def dhcpv6_callback(pkt):
    global dhcpv6_server_mac
    global dhcpv6_server_ipv6_link
    global dhcpv6_server_duid

    if pkt.haslayer(DHCP6_Advertise) or pkt.haslayer(DHCP6_Reply):
        if pkt[DHCP6OptServerId].duid is None:
            return False
        else:
            dhcpv6_server_mac = pkt[Ether].src
            dhcpv6_server_ipv6_link = pkt[IPv6].src
            dhcpv6_server_duid = pkt[DHCP6OptServerId].duid
            return True
    else:
        return False 
開發者ID:raw-packet,項目名稱:raw-packet,代碼行數:17,代碼來源:dnsmasploit.py

示例9: postcondition2

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def postcondition2(packet):
        from scapy.all import IPv6
        pkt = IPv6(packet.get_payload())
        if pkt.haslayer('IPv6'):
            del pkt['IPv6'].plen
        if pkt.haslayer('TCP'):
            del pkt['TCP'].chksum
        if pkt.haslayer('ICMP'):
            del pkt['ICMP'].chksum
        pkt.show2()
        packet.raw = bytes(pkt)
        return packet 
開發者ID:shramos,項目名稱:polymorph,代碼行數:14,代碼來源:cli.py

示例10: get_mac6

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def get_mac6(ip, interface):
    """Returns the according MAC address for the provided IPv6 address.

    Args:
        ip (str): IPv6 address used to get MAC address.
        interface (str): Interface used to send neighbor solicitation.

    Results:
        According MAC address as string (11:22:33:44:55:66)
        or None if no answer has been received.
    """
    ans, unans = srp(Ether(dst=ETHER_BROADCAST) / IPv6(dst=ip) / ICMPv6ND_NS(tgt=ip), timeout=2, iface=interface, inter=0.1, verbose=0)
    for snd, rcv in ans:
        return rcv.sprintf(r"%Ether.src%") 
開發者ID:usableprivacy,項目名稱:upribox,代碼行數:16,代碼來源:util.py

示例11: is_spoof_dns

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def is_spoof_dns(ipv6):
    """Checks if it is necessary to additionally spoof the address of the DNS server.
    The DNS server needs to be spoofed if it is on the own network and if it is not
    the default gateway (this is already used for spoofing).

    Args:
        ipv6 (namedtuple): Contains various IPv6 information.
        ipv6.dns_servers (list): List containing the IP addresses of DNS servers as String.
        ipv6.network (netaddr.IPNetwork): IPNetwork object representing the IPv6 network.
        ipv6.gateway (str): IPv6 address of the default gateway.

    Results:
        True if configured DNS server uses a global address and is on own network
        or DNS server uses link-local address and is not also the gateway.
    """
    return ipv6.dns_servers[0] in ipv6.network or (IPAddress(ipv6.dns_servers[0]).is_link_local()
                                                   and ipv6.dns_servers[0] != ipv6.gateway)


# class IPInfo(object):
#
#     def __init__(self, ip, netmask, network, gateway, mac, gate_mac, dns_servers, redis):
#         self.ip = ip
#         self.netmask = netmask
#         self.mac = mac
#         self.network = network
#         self.gateway = gateway
#         self.gate_mac = gate_mac
#         self.dns_servers = dns_servers
#         self.redis = redis 
開發者ID:usableprivacy,項目名稱:upribox,代碼行數:32,代碼來源:util.py

示例12: _return_to_normal

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def _return_to_normal(self):
        """This method is called when the daemon is stopping.
        First, sends a GARP broadcast request to all clients to tell them the real gateway.
        Then ARP replies for existing clients are sent to the gateway.
        If IPv6 is enabled, Apate tells the clients the real gateway via neighbor advertisements.
        """
        # spoof clients with GARP broadcast request

        with self.sleeper:
            sendp(
                Ether(dst=ETHER_BROADCAST) / ARP(op=1, psrc=self.ipv4.gateway, pdst=self.ipv4.gateway, hwdst=ETHER_BROADCAST,
                                                 hwsrc=self.ipv4.gate_mac)) 
開發者ID:usableprivacy,項目名稱:upribox,代碼行數:14,代碼來源:daemon_process.py

示例13: run

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def run(self):
        """Sends ICMPv6 echo request packets marked with the data upribox to the
        IPv6 all nodes multicast address.
        Received echo replies are processed by a SniffThread.
        """
        while True:
            send(IPv6(dst=self._MULTICAST_DEST) / ICMPv6EchoRequest(data=self._DATA), iface=self.interface)
            time.sleep(self._SLEEP) 
開發者ID:usableprivacy,項目名稱:upribox,代碼行數:10,代碼來源:misc_thread.py

示例14: get_local_ipv6_address

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def get_local_ipv6_address():
    """Return IPv6 address of local node."""
    sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
    sock.connect(("::1", 80))
    local_ip = sock.getsockname()[0]
    sock.close()
    return local_ip 
開發者ID:Samsung,項目名稱:cotopaxi,代碼行數:9,代碼來源:common_utils.py

示例15: ssdp_send_query

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import IPv6 [as 別名]
def ssdp_send_query(test_params, query):
    """Send SSDP query to normal and multicast address."""
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    if test_params.ip_version == 4:
        sock.sendto(
            query.encode(), (SSDP_MULTICAST_IPV4, test_params.dst_endpoint.port)
        )
        sent_time = test_params.report_sent_packet()
        sock.settimeout(test_params.timeout_sec)
        try:
            while True:
                data, addr = sock.recvfrom(INPUT_BUFFER_SIZE)
                print_verbose(
                    test_params,
                    "Received response from {} - content:\n{}\n-----".format(
                        addr, data
                    ),
                )
                if (
                    test_params.dst_endpoint.ip_addr,
                    test_params.dst_endpoint.port,
                ) == addr:
                    print_verbose(
                        test_params, "This is the response that we was waiting for!"
                    )
                    test_params.report_received_packet(sent_time)
                    return data
                else:
                    print_verbose(
                        test_params, "Received response from another host (not target)!"
                    )
        except socket.timeout:
            print_verbose(test_params, "Received no response!")

    elif test_params.ip_version == 6:
        print ("IPv6 is not supported for SSDP")
    return None 
開發者ID:Samsung,項目名稱:cotopaxi,代碼行數:39,代碼來源:common_utils.py


注:本文中的scapy.all.IPv6方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。