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))


运行结果图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值