Exemplo n.º 1
0
def main():
    if len(sys.argv) != 3:
        usage()
        sys.exit()

    interface = sys.argv[1]
    seconds = int(sys.argv[2])

    addresses = netifaces.ifaddresses(interface)
    src_mac = addresses[netifaces.AF_LINK][0]['addr']
    src_ip = addresses[netifaces.AF_INET][0]['addr']

    dest_mac = "55:55:55:55:55:55" # dummy MAC
    dest_ip = "5.5.5.5" # dummy IP

    start_time = datetime.now()
    timestamps = []

    while millis(start_time) < seconds*1000:
        packet = arp.create_arp_packet(src_mac,
                                       src_ip,
                                       dest_mac,
                                       dest_ip,
                                       arp.ARP_REPLY)
        arp.send_arp_packet(packet)
        timestamps.append(millis(start_time))

    pp.plot(timestamps, len(timestamps)*[1], "x")
    pp.savefig('flood_packets_output.png')

    print "%d reply packets send" % len(timestamps)
    print "Each packet has size: 28(ARP header) + 14(Ethernet header) bytes= 42"
    print "Transmission rate: %f bytes/second" % (len(timestamps)*42.0/seconds)
Exemplo n.º 2
0
def main():
    if len(sys.argv) != 5:
        usage()
        sys.exit()

    interface = sys.argv[1]
    dest_mac = sys.argv[2]
    dest_ip = sys.argv[3]
    seconds = int(sys.argv[4])

    addresses = netifaces.ifaddresses(interface)
    src_mac = addresses[netifaces.AF_LINK][0]['addr']
    src_ip = addresses[netifaces.AF_INET][0]['addr']

    start_time = datetime.now()
    timestamps = []
    while millis(start_time) < seconds * 1000:
        packet = arp.create_arp_packet(src_mac, src_ip, dest_mac, dest_ip,
                                       arp.ARP_REQUEST)
        arp.send_arp_packet(packet)
        timestamps.append(millis(start_time))

        # Sleep for a random amount of time
        time.sleep(random.uniform(0, 2.0))

    pp.plot(timestamps, len(timestamps) * [1], "x")
    pp.xlabel("Timestamps")
    pp.ylabel("Packets sent count")
    pp.savefig('send_packets_output.png')

    print "%d packets send" % len(timestamps)
Exemplo n.º 3
0
 def packet_handler(packet):
     if packet[ARP].pdst == new_ip and \
        packet[ARP].op == arp.ARP_REQUEST:
         reply_packet = arp.create_arp_packet(new_mac,
                                              new_ip,
                                              packet[ARP].hwsrc,
                                              packet[ARP].psrc,
                                              arp.ARP_REPLY)
         print packet[ARP].hwsrc
         print packet[ARP].psrc
         arp.send_arp_packet(reply_packet)
Exemplo n.º 4
0
def main():
    if len(sys.argv) != 6:
        usage()
        sys.exit()

    src_ip = sys.argv[1]
    src_mac = sys.argv[2]
    dest_ip = sys.argv[3]
    dest_mac = sys.argv[4]
    seconds = int(sys.argv[5])

    start_time = datetime.now()

    while millis(start_time) < seconds*1000:
        packet = arp.create_arp_packet(src_mac,
                                       src_ip,
                                       dest_mac,
                                       dest_ip,
                                       arp.ARP_REPLY)
        arp.send_arp_packet(packet)
Exemplo n.º 5
0
def main():
    if len(sys.argv) != 4:
        usage()
        sys.exit()

    interface = sys.argv[1]
    dest_ip = sys.argv[2]
    arp_reply_wait_time = int(sys.argv[3])

    addresses = netifaces.ifaddresses(interface)
    src_mac = addresses[netifaces.AF_LINK][0]['addr']
    src_ip = addresses[netifaces.AF_INET][0]['addr']

    ip_mac_count = {}

    def packet_handler(packet):
        print(packet[ARP].psrc)
        if packet[ARP].op == arp.ARP_REPLY and \
           packet[ARP].psrc == dest_ip:
            if packet[ARP].hwsrc in ip_mac_count:
                ip_mac_count[packet[ARP].hwsrc] += 1
            else:
                ip_mac_count[packet[ARP].hwsrc] = 1

    packet = arp.create_arp_packet(src_mac,
                                   src_ip,
                                   "FF:FF:FF:FF:FF:FF",
                                   dest_ip,
                                   arp.ARP_REQUEST)
    arp.send_arp_packet(packet)

    arp.sniff_arp_packets(callback=packet_handler,
                          timeout=arp_reply_wait_time/1000)

    print "Packets received:"
    for mac in ip_mac_count:
        print "Mac Address: %s, count = %d" % (mac, ip_mac_count[mac])