Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """ ##### Address Resolution protocol #####
- __________________________________________________
- |################################################ /|
- | ethernet broadcast |#| --> 6 bytes
- |------------------------------------------------|#|
- | ethernet sender mac |#| --> 6 bytes
- |------------------------------------------------|#|
- | ethernet protocol type |#| --> 2 bytes
- |------------------------------------------------|#|
- | hardware type |#| --> 2 bytes
- |------------------------------------------------|#|
- | protocol protocol |#| --> 2 bytes
- |------------------------------------------------|#|
- | mac address length || length protocol |#| --> 2 bytes
- |------------------------------------------------|#|
- | operation number |#| --> 2 bytes
- |------------------------------------------------|#|
- | sender mac address |#| --> 6 bytes
- |------------------------------------------------|#|
- | sender IPv4 address |#| --> 4 bytes
- |------------------------------------------------|#|
- | \x00\x00\x00\x00\x00\x00 |#| --> 6 bytes
- |------------------------------------------------|#|
- | receive IPv4 address |#| --> 4 bytes
- +________________________________________________|/
- Packet size 42 bytes
- """
- from struct import *
- import socket
- dst = b'\xff\xff\xff\xff\xff\xff' # 6 bytes
- src = b'\x74\x29\xaf\xa1\xef\x67' # 6 bytes
- pro = 0x0806 # 2 bytes
- htype = 0x01 # 2 bytes
- ptype = 0x0800 # 2 bytes
- hsize = 0x06 # 1 byte
- psize = 0x04 # 1 byte
- op = 0x01 # 2 bytes
- shwa = b'\x74\x29\xaf\xa1\xef\x67' # 6 bytes
- spa = socket.inet_aton('192.168.0.8') # 4 bytes
- thwa = b'\x00\x00\x00\x00\x00\x00' # 6 bytes
- tpa = socket.inet_aton('192.168.0.1') # 4 bytes
- ether_frame = pack('!6s6sH', dst, src, pro)
- arp_frame = pack('!HHBBH6s4s6s4s', htype, ptype, hsize, psize, op, shwa, spa, thwa, tpa)
- # pacote arp
- packet = ether_frame + arp_frame
- sock = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(0x0806))
- sock.bind(('wlan0', 0))
- count = 0
- while count != 5:
- count += 1
- try:
- # envia o pacote
- sock.send(packet)
- # espera a resposta
- sock.settimeout(0.5)
- response = sock.recvfrom(42)[0]
- if response:
- print(response)
- except socket.timeout:
- print("Tentativa %i não obteve resposta" % count)
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement