Skip to content

feat(cli): add --geo flag for client location tracking#5

Merged
ssmirr merged 5 commits intossmirr:masterfrom
paradixe:feat/geo-tracking
Jan 29, 2026
Merged

feat(cli): add --geo flag for client location tracking#5
ssmirr merged 5 commits intossmirr:masterfrom
paradixe:feat/geo-tracking

Conversation

@paradixe
Copy link

Adds --geo flag to track where clients connect from.

Usage:

conduit start --geo --stats-file

stats.json output:

{
  "connectedClients": 12,
  "geo": [
    {"code": "IR", "country": "Iran", "count": 234},
    {"code": "DE", "country": "Germany", "count": 45}
  ]
}

How it works:

  • Runs tcpdump in background (every 60s)
  • Looks up IPs with geoiplookup
  • Includes results in stats.json

Requirements:

apt install tcpdump geoip-bin

Disabled by default. No impact when not used.

Adds optional geo tracking via tcpdump + geoiplookup.
When enabled, stats.json includes country breakdown.

Usage: conduit start --geo --stats-file
@paradixe
Copy link
Author

@ssmirr for your review

@0xf00f00
Copy link

I built a little tool here to help me view connections on a map with some basic info: https://github.com/0xf00f00/conntrack-monitor

sharing it here in case someone finds it useful. maybe we could add a list of these tools to readme.

@rezaneam
Copy link

@ssmirr could you please prioritize this PR?

@paradixe
Copy link
Author

paradixe commented Jan 28, 2026

@ssmirr could you please prioritize this PR?

While he's reviewing, I have a standalone script you can use with with any conduit installation, and has the same capability in terminal:

apt install -y geoip-bin tcpdump && curl -sSL https://raw.githubusercontent.com/paradixe/conduit-relay/main/geo-stats.sh | bash

@ssmirr
Copy link
Owner

ssmirr commented Jan 28, 2026

@rezaneam this is next on my list after #11 , multi instance could be very important for the performance so I'd prioritize that.

@ssmirr
Copy link
Owner

ssmirr commented Jan 29, 2026

Thank you for this PR @paradixe it was a great start on this feature! My main concerns are:

  1. this requires system level dependencies (is not cross platform either)
  2. requires privileged access
  3. is not accurate (the traffic is not just the conduit traffic).

I started a WIP fix for this, which I will clean up and push to this branch tomorrow. The code captures the IPs and uses a golang package to determine the location. The combination of these two things resolves issues I mentioned above.

in addition to resolving the items above we can now see exactly how much traffic and how many connections are coming through a TURN relay (i.e. we don't know the actual location, we only know when the relay is)

Replaces external tcpdump + geoiplookup dependencies with pure Go
implementation using MaxMind GeoLite2 database. No sudo required,
cross-platform, all 249 countries supported.

Connection tracking flow:

  Connect ──► OnConnectionEstablished ──► ConnectIP(ip)
                                               │
                                               ▼
                                      GeoIP2 lookup + live++
      │
      │ (connection active...)
      │
  Close ───► OnConnectionClosed ──► DisconnectIP(ip, bytesUp, bytesDown)
                                               │
                                               ▼
                                      live-- + accumulate bytes

Stats per country:
- count: currently connected (live)
- count_total: unique IPs since start
- bytes_up/down: total bandwidth since start

TURN relay connections tracked as code=RELAY (country unknown).

Example stats.json geo output:

  {
    "geo": [
      {
        "code": "IR",
        "country": "Iran",
        "count": 3,
        "count_total": 47,
        "bytes_up": 524288000,
        "bytes_down": 2684354560
      },
      {
        "code": "RELAY",
        "country": "Unknown (TURN Relay)",
        "count": 1,
        "count_total": 8,
        "bytes_up": 52428800,
        "bytes_down": 268435456
      }
    ]
  }
@ssmirr
Copy link
Owner

ssmirr commented Jan 29, 2026

Ready to merge. Thanks again for getting this started!

@ssmirr ssmirr merged commit f8be6a2 into ssmirr:master Jan 29, 2026
ssmirr added a commit that referenced this pull request Jan 29, 2026
* feat(cli): add --geo flag for client location tracking

Adds optional geo tracking via tcpdump + geoiplookup.
When enabled, stats.json includes country breakdown.

Usage: conduit start --geo --stats-file

* fix: simplify isPrivateIP check

* Replace tcpdump-based geo tracking with GeoIP2 database

Replaces external tcpdump + geoiplookup dependencies with pure Go
implementation using MaxMind GeoLite2 database. No sudo required,
cross-platform, all 249 countries supported.

Connection tracking flow:

  Connect ──► OnConnectionEstablished ──► ConnectIP(ip)
                                               │
                                               ▼
                                      GeoIP2 lookup + live++
      │
      │ (connection active...)
      │
  Close ───► OnConnectionClosed ──► DisconnectIP(ip, bytesUp, bytesDown)
                                               │
                                               ▼
                                      live-- + accumulate bytes

Stats per country:
- count: currently connected (live)
- count_total: unique IPs since start
- bytes_up/down: total bandwidth since start

TURN relay connections tracked as code=RELAY (country unknown).

Example stats.json geo output:

  {
    "geo": [
      {
        "code": "IR",
        "country": "Iran",
        "count": 3,
        "count_total": 47,
        "bytes_up": 524288000,
        "bytes_down": 2684354560
      },
      {
        "code": "RELAY",
        "country": "Unknown (TURN Relay)",
        "count": 1,
        "count_total": 8,
        "bytes_up": 52428800,
        "bytes_down": 268435456
      }
    ]
  }

* Update README: geo tracking no longer requires tcpdump/sudo

* Document geo stats behavior and remove debug logging

---------

Co-authored-by: Samim Mirhosseini <ssmirr@users.noreply.github.com>
netirdev pushed a commit to netirdev/conduit that referenced this pull request Feb 5, 2026
* feat(cli): add --geo flag for client location tracking

Adds optional geo tracking via tcpdump + geoiplookup.
When enabled, stats.json includes country breakdown.

Usage: conduit start --geo --stats-file

* fix: simplify isPrivateIP check

* Replace tcpdump-based geo tracking with GeoIP2 database

Replaces external tcpdump + geoiplookup dependencies with pure Go
implementation using MaxMind GeoLite2 database. No sudo required,
cross-platform, all 249 countries supported.

Connection tracking flow:

  Connect ──► OnConnectionEstablished ──► ConnectIP(ip)
                                               │
                                               ▼
                                      GeoIP2 lookup + live++
      │
      │ (connection active...)
      │
  Close ───► OnConnectionClosed ──► DisconnectIP(ip, bytesUp, bytesDown)
                                               │
                                               ▼
                                      live-- + accumulate bytes

Stats per country:
- count: currently connected (live)
- count_total: unique IPs since start
- bytes_up/down: total bandwidth since start

TURN relay connections tracked as code=RELAY (country unknown).

Example stats.json geo output:

  {
    "geo": [
      {
        "code": "IR",
        "country": "Iran",
        "count": 3,
        "count_total": 47,
        "bytes_up": 524288000,
        "bytes_down": 2684354560
      },
      {
        "code": "RELAY",
        "country": "Unknown (TURN Relay)",
        "count": 1,
        "count_total": 8,
        "bytes_up": 52428800,
        "bytes_down": 268435456
      }
    ]
  }

* Update README: geo tracking no longer requires tcpdump/sudo

* Document geo stats behavior and remove debug logging

---------

Co-authored-by: Samim Mirhosseini <ssmirr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants