ethernet和arp协议学习

ethernetii关键报文:

目的地址(dmac) 6bytes

源地址(smac) 6bytes

类型字段(type) 2bytes 上层数据的类型 ip:0x800,arp:0x0806

数据字段(data) 最少为46bytes保证帧长为64bytes

填充字段(padding) 数据小于46bytes时,进行填充

校验和(fcs) 4bytes

wireshark抓包

arp协议:是ip与ethernet之间的映射协议,ethernet 硬件地址mac地址,ip 逻辑地址 ip地址

工作流程:

当数据包封装时,会查询本地的arp缓存,如果ip在arp缓存中,则直接封装mac与ip地址

查不到时,会发arp请求ip对应的mac

当目标mac的主机收到arp请求时,会响应对应的arp应答报文

arp关键报文:

hwtype = Ethernet (10Mb) 硬件类型

ptype = IPv4 协议类型

hwlen = None 硬件地址

plen = None 逻辑地址

op = who-has 1请求,2是应答

hwsrc = 80:45:dd:ab:a2:89 源mac地址

psrc = 192.168.0.103 源ip

hwdst = 00:00:00:00:00:00 目的mac地址

pdst = 0.0.0.0 目的ip

arp wireshark 请求包

响应包

arp扫描



from  scapy.all import *
ifcace='VMware Virtual Ethernet Adapter for VMnet8'           
ip=['192.168.85.{}'.format(str(i)) for i in range(120,140)]
for dip in ip:
    arp_p=Ether()/ARP(pdst=dip)           

    p=srp(arp_p,iface=ifcace,verbose=0,timeout=2)    #指定网卡,关闭详细信息展示,设置超时时间
for req,rep in p[0]:
print('{}存活,mac为{}'.format(dip,rep[ARP].hwsrc))  
for req in p[1]:
print('{}不存活'.format(dip))


运行结果图

posted @ 2023-11-28 15:00  mushangqiujin  阅读(75)  评论(0)    收藏  举报  来源