Exemple #1
0
def catch_ping_reply(s, ID, time_sent, timeout=1):
    # create while loop
    while True:
        starting_time = time.time()  # Record Starting Time
        # to handle timeout function of socket
        process = select.select([s], [], [], timeout)
        # check if timeout
        if not process[0]:
            return calc_rtt(time_sent), None, None
        # receive packet
        rec_packet, addr = s.recvfrom(1024)
        icmp_type = rec_packet[20]
        if icmp_type == 11:
            icmp = parse_icmp_header(rec_packet[48:56])
        else:
            icmp = parse_icmp_header(rec_packet[20:28])
        # check identification
        if icmp['id'] == ID:
            icmp['type'] = icmp_type
            return calc_rtt(time_sent), parse_ip_header(rec_packet[:20]), icmp
def catch_ping_reply(s, ID, time_sent, timeout=1):
    # create while loop
    while True:
        starting_time = time.time()  # Record Starting Time

        # to handle timeout function of socket
        process = select.select([s], [], [], timeout)

        # check if timeout
        if not process[0]:
            s.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
            # Request sent
            global addr
            global curr_addr

            ID = single_ping_request(s, addr)

            # receive packet
            try:
                s.settimeout(1)
                rec_packet, curr_addr = s.recvfrom(1024)

            except socket.error:
                return calc_rtt(time_sent), None, None
                # pass

            # extract icmp packet from received packet
            icmp = parse_icmp_header(rec_packet[20:28])

            return calc_rtt(time_sent), parse_ip_header(rec_packet[:20]), icmp
        else:
            # receive packet
            rec_packet, curr_addr = s.recvfrom(1024)
            # extract icmp packet from received packet
            icmp = parse_icmp_header(rec_packet[20:28])
            # check identification
            if icmp['id'] == ID:
                return calc_rtt(time_sent), parse_ip_header(
                    rec_packet[:20]), icmp
Exemple #3
0
def icmp_test():
    icmp = ICMPPacket()
    print(parse_icmp_header(icmp.raw))
    ip = load_ip(tcp=icmp, ip_proto=socket.IPPROTO_ICMP)
    eth = EtherPacket(data=ip)

    try:
        from ..samples.wsk import ShowPacket
        pkt = eth.raw + ip.raw + icmp.raw
        ShowPacket([pkt], link_type=1)
    except Exception as e:
        print(e)
        print("[+] Unable To Find pye.samples.wsk script.")
    return
Exemple #4
0
def catch_trace_reply(s, ID, time_sent, timeout=10):
    # create while loop
    while True:
        starting_time = time.time()  # Record Starting Time

        # to handle timeout function of socket
        process = select.select([s], [], [], timeout)

        # check if timeout
        if not process[0]:
            return calc_rtt(time_sent), None, None

        # receive packet
        rec_packet, addr = s.recvfrom(2048)

        # extract icmp packet from received packet
        icmp = parse_icmp_header(rec_packet[20:28])

        # check identification
        if icmp['id'] == ID:
            return calc_rtt(time_sent), parse_ip_header(rec_packet[:20]), icmp
Exemple #5
0
def catch_ping_reply(s, ID, time_sent, timeout=1):
    TTL = 0
    while True:
        TTL += 1
        starting_time = time.time()  # Record Starting Time
        # to handle timeout function of socket
        process = select.select([s], [], [], timeout)
        # check if timeout
        if not process[0]:
            return calc_rtt(time_sent), None, None

        # receive packet
        rec_packet, addr = s.recvfrom(1024)

        # extract icmp packet from received packet
        icmp = parse_icmp_header(rec_packet[20:28])
        reply = parse_ip_header(rec_packet[:20])
        # check identification
        if icmp['id'] == ID:
            return calc_rtt(time_sent), reply, icmp
        else:
            print(reply['TTL'])