简体   繁体   English

没有回复的 ARP 请求 raw sockets python

[英]ARP request without reply raw sockets python

I'm trying to get a arp reply after send ARP request but the reply is not comming.我试图在发送 ARP 请求后获得 arp 回复,但没有收到回复。

I had a look to wireshark for the results and i think he does the broadcast to the.network, but no reply show up...我查看了 wireshark 的结果,我认为他向.network 广播,但没有回复显示...

In results of wireshark the MAC addr of sender and receiver is do not correspond to the real MAC addr, im bealive i'm not packing this right but i dont understand why.在 wireshark 的结果中,发送方和接收方的 MAC 地址与真实的 MAC 地址不对应,我相信我没有正确打包,但我不明白为什么。

need help...需要帮忙...

#!/usr/bin/env python3

import struct
import socket



raw = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0806))
raw.bind(("wlp3s0", socket.htons(0x0806)))


mac_local = b"ff:ff:ff:ff:ff:ff"   # mac de quem envia request
ip_local = "192.168.1.7"           # ip de quem envia request
mac_dest = b"00:00:00:00:00:00"    # mac de quem recebe request
ip_dest = "192.168.1.2"            # ip de quem recebe request




# Ethernet Header
protocol = 0x0806             # 0x0806 protocol to ARP
ethernet_header = struct.pack("!6s6sH", mac_dest, mac_local, protocol)


# ARP header

type_hardware = 1
type_protocol = 0x0800       # IPV4
size_addr_hardware = 6   # Refere ao tamanho do endereço do MAC que é 
48 bits  == 6 bytes 
size_addr_protocol = 4  # Refere ao tamanho do endereço do ipv4 que é 
32 bits == 4 bytes
operation = 1                  # 1 = request / 2 = Reply 

source_ip = socket.inet_aton(ip_local)
dest_ip = socket.inet_aton(ip_dest)


arp_addr = struct.pack("!HHBBH6s4s6s4s", type_hardware, type_protocol,
                       size_addr_hardware, size_addr_protocol, operation,
                       mac_local, source_ip, mac_dest, dest_ip)
pkt = ethernet_header + arp_addr

cont = 0
while cont < 6:
    raw.send(pkt)
    cont +=1

enter image description here在此处输入图像描述

enter image description here在此处输入图像描述

mac_dest and mac_local are definitely not right. mac_destmac_local绝对不正确。 You've just created a byte string with the ASCII value. 您刚刚使用ASCII值创建了一个字节字符串。 Each of those is 17 bytes long. 这些每个都是17字节长。 And you're just taking the first 6 of those 17 bytes for each of the addresses. 而且,您只需要为每个地址获取这17个字节中的前6个字节。

They should be something like this instead: 它们应该是这样的:

mac_dest = b'\x00\x00\x00\x00\x00\x00'
mac_local = b'\xff\xff\xff\xff\xff\xff'

Check that the length of the byte string before the struct.pack call is exactly six bytes. 检查struct.pack调用之前字节字符串的长度是否正好是六个字节。

Also, not sure what you're trying to do, but I doubt it makes sense to use the all-zero hardware address as a destination address. 另外,不确定您要做什么,但是我怀疑使用全零硬件地址作为目标地址是否有意义。 Pretty sure no one will receive that as it would be a unicast to an address that no one has. 可以肯定的是没有人会收到它,因为它将是单播到一个没有人的地址。 The opposite might be helpful (send to the broadcast address from all-zero) -- I think that's standard for ARP probes. 相反可能会有所帮助( 全零发送到广播地址)-我认为这是ARP探针的标准。

I'm somehow confused about the accepted answer.我对接受的答案感到困惑。

Is MAC 00:00:00: 00:00:00 not a valid MAC from XEROX? MAC 00:00:00: 00:00:00 不是 XEROX 的有效 MAC 吗?

https://hwaddress.com/company/xerox-corporation/ https://hwaddress.com/company/xerox-corporation/

When I see ARP-request captured with eg wireshark当我看到使用 wireshark 捕获的 ARP 请求时

then mac adresses in requests are always like那么请求中的 mac 地址总是像

MAC_DST: FF:FF:FF:FF:FF:FF  //mac broadcast
MAC_SRC: MAC-address of requester

the mac adresses in reply would then be回复的mac地址将是

MAC_DST: MAC-adress of requester
MAC_SRC: MAC-address of replier

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM