由上面三种方式的实际操作和共同的实现原理,改造而来的一种获取远程主机mac的地址的实现方式
获取远程IP的mac地址最主要的操作就是通过抓包获取请求里面携带的网卡信息,然后分析得到其中的Dst和Src信息格式如下
Ethernet II, Src: f8:ff:c2:48:3d:6d (f8:ff:c2:48:3d:6d), Dst: Hangzhou_54:80:02 (38:97:d6:54:80:02)
要想抓包得到结构就必须要有一步服务器之间要有通讯,就是在抓包开始的那个时间开始服务器之间要有至少一次的通讯才可以,也就是说 抓包->ping host->抓包结束->得到结果这样一个步骤
由于抓包的得到的结构都是.cap后缀 直接读取的话是一堆乱码经过分析之后可以得到mac地址分别为:
fa 16 3e c8 fe 8f
fa 16 3e b5 33 2f
但是不好区分,其他的字符也不确定是什么意思,估计是转码的时候格式不一样吧
d4 c3 b2 a1 2 0 4 0 0 0 0 0 0 0 0 0 0 0 4 0 1 0 0 0 ad d4 bd 5f 15 9a 2 0 62 0 0 0 62 0 0 0 fa 16 3e c8 fe 8f fa 16 3e b5 33 2f 8 0 45 0 0 54 de 1b 40 0 40 1 d4 e0 c0 a8 0 5 81 cc 45 33 8 0 c3 9e f bf 0 1 ad d4 bd 5f 0 0 0 0 f8 99 2 0 0 0 0 0 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37
转码的方法为:
private static String byteReadStr(byte[] mac) { StringBuffer sb = new StringBuffer(""); StringBuffer sbby = new StringBuffer(""); for(int i=0; i
后来我经过研究之后又发现了一种操作方式 就是借助第三方工具tshark进行分析.cap的抓包文件,可以得到如下信息
Frame 1: 98 bytes on wire (784 bits), 98 bytes captured (784 bits) Encapsulation type: Ethernet (1) Arrival Time: Nov 25, 2020 11:51:09.170517000 CST [Time shift for this packet: 0.000000000 seconds] Epoch Time: 1606276269.170517000 seconds [Time delta from previous captured frame: 0.000000000 seconds] [Time delta from previous displayed frame: 0.000000000 seconds] [Time since reference or first frame: 0.000000000 seconds] Frame Number: 1 Fr.........