Exemple #1
0
def standard_arp_request(dst_ipaddr):
    try:
        sock = rawsocket.socket(EthernetHeader.TYPE_ARP)
    except IOError:
        print "Login as root, or you won't be able to make a raw socket"
        raise IOError

    a = ArpPacket()

    eth = a.previous
    eth.dst_mac = 0xFFFFFFFFFFFFL
    eth.src_mac = my_macaddr
    eth.packet_type = EthernetHeader.TYPE_ARP

    a.arp_hw = ArpPacket.HW_ETHER
    a.ethernet_type = EthernetHeader.TYPE_IP
    a.arp_opcode = ArpPacket.OPCODE_REQUEST
    a.src_hw_addr = my_macaddr
    a.src_prot_addr = my_ipaddr
    a.dst_hw_addr = 0xFFFFFFFFFFFFL
    a.dst_prot_addr = dst_ipaddr
    rawsocket.sendto(sock, a.bytes())
    x = rawsocket.recvfrom(sock)
    x = a.extract(x)
    arptable[dst_ipaddr] = a.src_hw_addr
Exemple #2
0
def test_udp(byte):

    if not arptable.has_key(bd_ipaddr):
        standard_arp_request(bd_ipaddr)

    try:
        sock = rawsocket.socket(EthernetHeader.TYPE_IP)
    except IOError:
        print "Login as root, or you won't be able to make a raw socket"
        raise IOError

    cmd = "\xff" + ((byte and "\x01") or "\x00")

    u = UdpPacket(my_ipaddr, 43700,
                  bd_ipaddr, 5000, cmd)
    print "IP COMMAND TO BOARD"
    u.dump()
    rawsocket.sendto(sock, u.bytes())
    x = rawsocket.recvfrom(sock)
    oldtype = u.previous.previous.packet_type
    x = u.extract(x)
    assert u.previous.previous.packet_type == oldtype
    print "\nIP RESPONSE FROM BOARD"
    u.dump()
    if x:
        print len(x), "bytes left over"
Exemple #3
0
def test_arp():

    try:
        sock = rawsocket.socket(EthernetHeader.TYPE_ARP)
    except IOError:
        print "Login as root, or you won't be able to make a raw socket"
        raise IOError

    a = ArpPacket()

    eth = a.previous
    eth.dst_mac = bd_macaddr
    eth.src_mac = my_macaddr
    eth.packet_type = EthernetHeader.TYPE_ARP

    a.arp_hw = ArpPacket.HW_ETHER
    a.ethernet_type = EthernetHeader.TYPE_IP
    a.arp_opcode = ArpPacket.OPCODE_REQUEST
    a.src_hw_addr = my_macaddr
    a.src_prot_addr = my_ipaddr
    a.dst_hw_addr = bd_macaddr
    a.dst_prot_addr = bd_ipaddr

    print "ARP REQUEST"
    a.dump()

    # Send ARP request, receive ARP reply
    rawsocket.sendto(sock, a.bytes())
    x = rawsocket.recvfrom(sock)

    print "\nARP REPLY"
    x = a.extract(x)
    a.dump()

    if x:
        print len(x), "bytes left over"