Пример #1
0
def icmp_reply(pkt):
    """
    Reply to the packet which the sniffer capture.
    """
    if pkt[ARP].op == 1:
        ip = IP()
        ip.dst = pkt[ARP].psrc
        ip.src = pkt[ARP].pdst

        icmp = ICMP()
        icmp.type = 0

        send(ip / icmp)
def reply(pkt):
    """
    Reply to the packet which the sniffer capture.
    """
    if pkt[ICMP].type == 8:
        ip = IP()
        ip.dst = pkt[IP].src
        ip.src = pkt[IP].dst

        icmp = ICMP()
        icmp.id = pkt[ICMP].id
        icmp.seq = pkt[ICMP].seq
        icmp.type = 0

        raw = Raw()
        raw.load = pkt[Raw].load

        send(ip / icmp / raw)
def print_pkt(pkt):
    if (pkt[ICMP].type == 8):
        eth = Ether()
        eth.dst = pkt[Ether].src
        eth.src = pkt[Ether].dst

        ip = IP()
        ip.dst = pkt[IP].src
        ip.src = pkt[IP].dst
        ip.ihl = pkt[IP].ihl

        icmp = ICMP()
        icmp.id = pkt[ICMP].id
        icmp.seq = pkt[ICMP].seq
        icmp.type = 0

        raw = Raw()
        raw.load = pkt[Raw].load

        send(eth / ip / icmp / raw)
Пример #4
0
def cmd_ping(ip_dst, ip_src, seq, icmp_id):
    conf.verb = False

    layer3 = IP()
    layer3.src = ip_src
    layer3.dst = ip_dst
    layer3.tos = 0
    layer3.id = 1
    layer3.flags = 0
    layer3.frag = 0
    layer3.ttl = 128
    layer3.proto = 1  # icmp

    layer4 = ICMP()
    layer4.type = 8  # echo-request
    layer4.code = 0
    layer4.id = icmp_id
    layer4.seq = seq
    pkt = layer3 / layer4 / b"abcdefghijklmn opqrstuvwabcdefg hi"
    send(pkt)
    print("Ping Sent")