Route¶
netutils.route
¶
Utilities to get best route from routing table.
NoRouteFound
¶
longest_prefix_match(ip_addr, routes)
¶
From a list of networks and an IP address, find the most specific route.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ip_addr |
str
|
String representation of an IP address. |
required |
routes |
List[Dict[str, str]]
|
list of dictionaries with network and mask as keys. Subnet can also be CIDR(number) notation. |
required |
Returns:
Type | Description |
---|---|
str
|
Longest Match Route |
Examples:
>>> from netutils.route import longest_prefix_match
>>> lookup = "10.1.1.245"
>>> routes = [{"network": "192.168.1.1", "mask": "255.255.255.255"},{"network": "10.1.1.0", "mask": "24"}]
>>> longest_prefix_match(lookup, routes)
'10.1.1.0/24'