0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cgncheck NAT特性調査ツール

0
Posted at

cgncheck — CGN (Carrier-Grade NAT) 特性調査ツール

モバイル回線等で「長時間アイドル後にVPNや通知が切れる」原因の切り分け用に作ったNAT測定用サーバとクライアントスクリプトです

  • NAPT の UDP/TCP セッションタイムアウト値の測定(適応二分探索)
  • 自回線の NAT 先アドレス確認: CGN 100.64.0.0/10、CLAT 192.0.0.0/29 の判定等、ローカル/マッピング先IP・ポートからの分類

クライアントはpython。Termux / Python があれば動きます。サーバーはrustバイナリ。

測定コマンド

デモサーバは https://cgncheck.host.usb0.net に立ててあります。

クライアントは負荷制限用トークンをhttpsエンドポイントで取得し、クライアント側から開いたUDP/TCP接続を複数維持してタイムアウトを探索します。
結果をサーバに自動ポストする機能をつけていますが、既定では送信せず --report 指定時のみ送信されます。

# UDP
python3 cgncheck.py --server https://cgncheck.host.usb0.net

# TCP
python3 cgncheck.py --server https://cgncheck.host.usb0.net --tcp

Termux 用ワンライナー

pkg install -y python curl && curl -LO 'https://raw.githubusercontent.com/ko-zu/cgncheck/refs/heads/main/clients/cgncheck.py' && python3 cgncheck.py --server https://cgncheck.host.usb0.net

出力例

$ python3 cgncheck.py --server https://cgncheck.host.usb0.net
UDP エンドポイント: x.x.x.x:8081
token: eyJjaWQiOiJjbGllbnQtZTE2NjZiYjM5ODA4OTc5NiIsImlhdCI6MTc4Nzg0MDI1NywiZXhwIjoxNzg3ODQwODU3fQ.aH2qo5jYHst1N4aeClT_ibQfWnrebwe-0yedV4jIpFk
=== NAPT チェック (echo rtt 1.3ms) ===
  local x.x.x.x:59802 (global) -> map x.x.x.x:59802 (global)  [none]
  判定: NAT/NAPT なし (直接接続)

測定範囲: 1s 〜 600.25s (N=2, flows=20, precision=0.5s, stagger=5s)
決め打ちグリッド 15点: 1s, 9.75s, 10.25s, 29.75s, 30.25s, 59.75s, 60.25s, 119.75s, 120.25s, 179.75s, 180.25s, 299.75s, 300.25s, 599.75s, 600.25s
[   1.0s]      1s probe 1/2 -> 生存
[   1.2s]      1s -> 生存
[   9.8s]   9.75s probe 1/2 -> 生存
[   9.8s]   9.75s -> 生存
[  10.0s] 飛行中: 10.25s, 29.75s, 30.25s, 59.75s, 60.25s, 119.75s, 120.25s, 179.75s, 180.25s, 240s, 299.75s, 300.25s, 337.687s, 375.125s, 412.562s, 450s, 487.437s, 524.875s, 599.75s, 600.25s (20/20ワーカー) 推定: TO > 9.75s
[  10.3s]  10.25s probe 1/2 -> 生存
[  10.4s]  10.25s -> 生存
[  20.0s] 飛行中: 29.75s, 30.25s, 59.75s, 60.25s, 119.75s, 120.25s, 179.75s, 180.25s, 240s, 299.75s, 300.25s, 337.687s, 375.125s, 412.562s, 450s, 487.437s, 524.875s, 562.312s, 599.75s, 600.25s (20/20ワーカー) 推定: TO > 10.25s
[  29.8s]  29.75s probe 1/2 -> 生存
[  29.8s]  29.75s -> 生存
[  30.0s] 飛行中: 30.25s, 59.75s, 60.25s, 119.75s, 120.25s, 179.75s, 180.25s, 210.125s, 240s, 299.75s, 300.25s, 337.687s, 375.125s, 412.562s, 450s, 487.437s, 524.875s, 562.312s, 599.75s, 600.25s (20/20ワーカー) 推定: TO > 29.75s
[  33.3s]  30.25s probe 1/2 -> 応答なし
[  38.3s]  30.25s probe 2/2 -> 応答なし
[  38.3s]  30.25s -> タイムアウト超過

測定点        ack    判定
1s         no     生存
9.75s      no     生存
10.25s     no     生存
29.75s     no     生存
30.25s     no     タイムアウト超過

NAPT 状況 (4フローで判定):
  local x.x.x.x:55616 (global) -> map x.x.x.x:55616 (global)  [none]
  local x.x.x.x:42376 (global) -> map x.x.x.x:42376 (global)  [none]
  local x.x.x.x:33362 (global) -> map x.x.x.x:33362 (global)  [none]
  local x.x.x.x:35638 (global) -> map x.x.x.x:35638 (global)  [none]
  判定: NAT/NAPT なし (直接接続)

C-W-S タイムアウト推定: 29.75s < TO <= 30.25s (48プローブ, 39s)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?