注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题

wateras1的个人空间 http://home.eeworld.com.cn/space-uid-361439.html [收藏] [复制] [分享] [RSS]

日志

linux /proc/net/arp 文件

已有 167 次阅读2018-5-30 10:32 |个人分类:MTK7688/7628 openwrt alexa

/proc/net/arp This holds an ASCII readable dump of the kernel ARP table used for address resolutions. It will show both dynamically learned and preprogrammed ARP entries. The format is: IP address HW type Flags HW address Mask Device 192.168.0.50 0x1 0x2 00:50:BF:25:68:F3 * eth0 192.168.0.250 0x1 0xc 00:00:00:00:00:00 * eth0 Here "IP address" is the IPv4 address of the machine and the "HW type" is the hardware type of the address from RFC 826. The flags are the internal flags of the ARP structure (as defined in /usr/include/linux/if_arp.h) and the "HW address" is the data link layer mapping for that IP address if it is known. /* ARP protocol HARDWARE identifiers. */ #define ARPHRD_NETROM 0 /* from KA9Q: NET/ROM pseudo */ #define ARPHRD_ETHER 1 /* Ethernet 10Mbps */ #define ARPHRD_EETHER 2 /* Experimental Ethernet */ #define ARPHRD_AX25 3 /* AX.25 Level 2 */ #define ARPHRD_PRONET 4 /* PROnet token ring */ #define ARPHRD_CHAOS 5 /* Chaosnet */ #define ARPHRD_IEEE802 6 /* IEEE 802.2 Ethernet/TR/TB */ #define ARPHRD_ARCNET 7 /* ARCnet */ #define ARPHRD_APPLETLK 8 /* APPLEtalk */ #define ARPHRD_DLCI 15 /* Frame Relay DLCI */ #define ARPHRD_ATM 19 /* ATM */ #define ARPHRD_METRICOM 23 /* Metricom STRIP (new IANA id) */ #define ARPHRD_IEEE1394 24 /* IEEE 1394 IPv4 - RFC 2734 */ #define ARPHRD_EUI64 27 /* EUI-64 */ #define ARPHRD_INFINIBAND 32 /* InfiniBand */ /* ARP Flag values. */ #define ATF_COM 0x02 /* completed entry (ha valid) */ #define ATF_PERM 0x04 /* permanent entry */ #define ATF_PUBL 0x08 /* publish entry */ #define ATF_USETRAILERS 0x10 /* has requested trailers */ #define ATF_NETMASK 0x20 /* want to use a netmask (only for proxy entries) */ #define ATF_DONTPUB 0x40 /* don't answer this addresses */

判断客户端在线方法:

有两种方式:

              一。通过DHCP client分配列表 (缺点:client列表会根据超时时间刷新,一般超时时间为12h,)

              二。通过arp缓存列表/proc/net/arp(缺点:arp刷新时间默认为30s,这个时间的误差可以接受。)


主要讲解第二种方法:

Flags: 0x0是找不到这台主机了。

             0x2是主机还在线。

[python] view plain copy
  1. IP address       HW type     Flags       HW address            Mask     Device  
  2. 192.168.235.1    0x1         0x2         00:01:41:80:e3:e9     *        eth0.2  
  3. 10.1.1.191       0x1         0x0         c4:6a:b7:6f:7a:db     *        br-lan  
  4. 10.0.2.148       0x1         0x2         c0:3f:d5:31:d8:b2     *        br-lan2  

所以根据这个flags就可以判断这台主机是否在线,统计非0的就好了。

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

Archiver|手机版|小黑屋|电子工程世界 ( 京ICP证 060456 )

GMT+8, 2019-6-25 05:50 , Processed in 0.038818 second(s), 11 queries , Gzip On, MemCache On.

Powered by EEWORLD电子工程世界

© 2019 http://bbs.eeworld.com.cn/

返回顶部