Is it a reliable way to get internet traffic from router using following script:
ROUTER_IP=$(ip route | grep default | awk '{print $3}')
WAN_PORT_INDEX=$(snmpget -L n -O qv -v2c -c public -m ALL $ROUTER_IP RFC1213-MIB::ipRouteIfIndex.0.0.0.0)
BYTES_IN=snmpget -c public -v2c 192.168.51.1 IF-MIB::ifInOctets.${WAN_PORT_INDEX}
BYTES_OUT=snmpget -c public -v2c 192.168.51.1 IF-MIB::ifOutOctets.${WAN_PORT_INDEX}
I've checked Mikrotik routers and an old cisco router with SNMP enabled RFC1213-MIB::ipRouteIfIndex.0.0.0.0 points to the WAN interface. Is that by accident or this is by design?