A route output text parser
Project description
routeparser: A route command output text parser
- It provides:
Reading text output of routes into Python objects
Simple identification of routes that match hosts or networks
- Installation:
pip install routeparser
- Usage:
example (where netstat_rn.txt is full output from ‘netstat -rn’ on Linux):
import routeparser # read lines from a file with open('netstat_rn.txt', 'r') as file_handle: lines = file_handle.readlines() # You can just get objects representing the routes if you wish: routes = routeparser.Route.from_linux_netstat_lines(lines) # These have attributes such as gateway, interface and network. # Some example values as in-line comments: routes[0].gateway # ipaddress.IPv4Address('192.168.1.1') routes[0].interface # 'eth0' routes[0].network # ipaddress.IPv4Network('10.10.0.0/16') # Route objects support membership testing: '10.10.10.1' in routes[0] # would return True, given the above example route # You can get a RoutingTable object from the lines: table = routeparser.RoutingTable.from_linux_netstat_lines(lines) # which you can then use to check for specific route matches: table.match('10.10.10.1') # would result in a matching Route object, if any # It supports string or Address/Network objects from the ipaddress module: import ipaddress table.match(ipaddress.ip_network('10.10.10.0/24')) # You can even get a list of all matching routes: table.matches('10.10.10.10') # Currently supported outputs and associated methods (for Route and RoutingTable) # Windows: # - 'route print': from_windows_route_print_lines # Linux: # - 'ip route': from_ip_route_lines # - 'netstat -r[nv]': from_linux_netstat_lines # - 'route [-n]': from_linux_route_lines
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
routeparser-0.0.1.tar.gz
(5.3 kB
view details)
Built Distribution
File details
Details for the file routeparser-0.0.1.tar.gz
.
File metadata
- Download URL: routeparser-0.0.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaf864389d3debdf9a215e70ace7b68a2fe9e47133339107dd9183128d8f16ad |
|
MD5 | 2ac0b1113357ecf6936e7647e0981406 |
|
BLAKE2b-256 | f7aa8d9b2aa223efc02a39a775468dbef3e8329b3826bae75ed48a1e961d0e7d |
File details
Details for the file routeparser-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: routeparser-0.0.1-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5764337ec2b8c9c4f3c39c69cb436122d07d3b30c20123180536a82d4702a67e |
|
MD5 | 8ab5e8221d0aa44f9859b0fdcae51b0c |
|
BLAKE2b-256 | 1df734b4bd7b622d23236809a53da378e75bea6b1abb9b68dc01ae0e8df0fc10 |