Linux 內部偵測 NAT 網路的有效方法

Linux 內部偵測 NAT 網路的有效方法

在Ubuntu中,我需要偵測網路IP位址是否為NAT系統,(不需要STUN)

我想像這樣檢查 ip 類別範圍類型:檢查IP位址是否在私網空間

但我看到了另一種方法,使用NETLINK_ROUTE從核心網路堆疊的路由表中取得本機ip系統

將此ip與外部可路由ip進行比較,如果相等則該網路不是nat系統

在 Perl 中,我找到了一個模組 IO::Socket::Netlink::Route,我測試並工作

https://metacpan.org/pod/release/PEVANS/Socket-Netlink-Route-0.05/lib/IO/Socket/Netlink/Route.pm

但閱讀 /sbin/ip 路由:

All operations with the ip route command are atomic, so each command will return either RTNETLINK answers

http://linux-ip.net/html/tools-ip-route.html

關於RTnetlink

Rtnetlink allows the kernel's routing tables to be read

https://man7.org/linux/man-pages/man7/rtnetlink.7.html

我已經使用 /sbin/ip 路由來獲取活動網路的主 ip,所以我想避免安裝另一個模組,而只是使用 ip 路由來檢測 NAT 系統。

我的做法正確嗎?

相關內容