Example #1
0
 def get_all_addrs(self):
     """
     Get all addresses for all links.
     """
     msg = rtnl_msg()
     msg.hdr.type = RTM_GETADDR
     msg.hdr.flags = NLM_F_DUMP | NLM_F_REQUEST
     return self.query_nl(msg)
Example #2
0
 def get_all_links(self):
     """
     Get info on all links.
     """
     msg = rtnl_msg()
     msg.hdr.type = RTM_GETLINK
     msg.hdr.flags = NLM_F_DUMP | NLM_F_REQUEST
     return self.query_nl(msg)
Example #3
0
 def get_all_neighbors(self):
     """
     Get all neighbors (ARP cache)
     """
     msg = rtnl_msg()
     msg.hdr.type = RTM_GETNEIGH
     msg.hdr.flags = NLM_F_DUMP | NLM_F_REQUEST
     msg.data.neigh.family = 2
     ptr = addressof(msg) + sizeof(nlmsghdr) + sizeof(ndmsg)
     return filter(lambda x: x['type'] == 'neigh', self.query_nl(msg,ptr - addressof(msg)))
Example #4
0
    def get_all_routes(self,table=254):
        """
        Get all routes. If no table number is specified, get records
        from the main routing table.

        Some default table numbers:
        0   -- unspec
        253 -- default
        254 -- main
        255 -- local
        """
        msg = rtnl_msg()
        msg.hdr.type = RTM_GETROUTE
        msg.hdr.flags = NLM_F_DUMP | NLM_F_REQUEST
        msg.data.route.family = 0
        msg.data.route.table = table
        ptr = addressof(msg.data) + sizeof(msg.data.route)
        return filter(lambda x: x['table'] == table, filter(lambda x: x['type'] == 'route', self.query_nl(msg,ptr - addressof(msg))))