#macos #routing #table #parser #ipv4 #ipv6 #gateway

macos-routing-table

macOS路由表解析器

1个不稳定版本

0.1.0 2024年3月11日

#29 in #ipv6

Apache-2.0

25KB
541 代码行

macos-routing-table

macOS设备的简单解析器和路由测试API。解析静态或实时路由表(通过netstat命令)并提供一个界面来检查该表,以及确定用于将流量路由到给定地址的网关和接口。

分析IPv4和IPv6路由表。对区域支持最少(目前只进行解析)。

示例 - 查找地址的网关

use anyhow::Result;
use macos_routing_table::{RouteEntry, RoutingTable};

#[tokio::main]
async fn main() -> Result<()> {
    let rt = RoutingTable::load_from_netstat().await?;
    let addr = "1.1.1.1".parse()?;

    if let Some(RouteEntry {
        net_if, gateway, ..
    }) = rt.find_route_entry(addr)
    {
        println!("{addr:?} => {gateway} via {net_if}");
    } else {
        println!("No route to {addr:?}");
    }

    Ok(())
}

依赖项

~4–11MB
~106K SLoC