Ejemplo n.º 1
0
def ICMPPortUnreachable(version, srcaddr, dstaddr, packet):
    if version == 4:
        # Linux hardcodes the ToS on ICMP errors to 0xc0 or greater because of
        # RFC 1812 4.3.2.5 (!).
        return ("ICMPv4 port unreachable",
                scapy.IP(src=srcaddr, dst=dstaddr, proto=1, tos=0xc0) /
                scapy.ICMPerror(type=3, code=3) / packet)
    else:
        return ("ICMPv6 port unreachable",
                scapy.IPv6(src=srcaddr, dst=dstaddr) /
                scapy.ICMPv6DestUnreach(code=4) / packet)
Ejemplo n.º 2
0
def get_icmp_unreachable_pkt(pkt):
    p = None
    icmp = None
    if pkt.ipv4:
        p = sp.IP(dst=pkt.src_addr, src=pkt.dst_addr)
        icmp = sp.ICMP()
        # ICMP type=3 code=3 port Unreachable
        icmp.type = 3
        icmp.code = 3
    else:
        p = sp.IPv6(dst=pkt.src_addr, src=pkt.dst_addr)
        icmp = sp.ICMPv6DestUnreach()
        # ICMP type=1 code=4 port Unreachable
        icmp.type = 1
        icmp.code = 4

    if pkt.ip.packet_len >= 64:
        return p / icmp / (bytes(pkt.raw)[0:64])
    else:
        return p / icmp / (bytes(pkt.raw))
 def GetIPv6Unreachable(port):
   return (scapy.IPv6(src="::1", dst="::1") /
           scapy.ICMPv6DestUnreach() /
           scapy.IPv6(src="::1", dst="::1") /
           scapy.ICMPv6EchoRequest(id=port, seq=1, data="foobarbaz"))