A tool to quickly determine the public IP address of a machine behind NAT with the help of STUN servers.
This tool is as simple as it sounds, when executed, it outputs the current machine's
public IP address by sending a binding request to the STUN server and displaying the
XOR-MAPPED-ADDRESS or MAPPED-ADDRESS attribute returned by the STUN server.
Either download pre-built binaries from the release page, or use cargo install uip to install it.
``` $ uip -h A tool to quickly determine the public IP address of a machine behind NAT with the help of STUN servers.
Usage: uip [HOST:PORT]
Arguments: [HOST:PORT] STUN server host and port. If PORT is omitted, it defaults to 3478 [default: stun.l.google.com:19302]
Options: -h, --help Print help -V, --version Print version ```
$ uip stun.l.google.com
203.0.113.1
$ uip stun.l.google.com:19302
203.0.113.1
This program use return code 0 to indicate success and a valid IP has been returned.
All other return code indicates error.
The program timeouts after 5 seconds in case a response can not be received.
To debug, run it with RUST_LOG=debug uip.
stun.l.google.comstun1.l.google.comstun2.l.google.comstun3.l.google.comstun4.l.google.comstun.syncthing.netstun.xten.comstun.qq.comstun.miwifi.compublic-stun-list.txt (Unverified)
This script was modified from the stun_client.rs
example of the WebRTC.rs project by Rain Liu yliu@webrtc.rs.
uip added better error handling, more friendly command line interface and fallback to MAPPED-ADDRESS attribute
in case XOR-MAPPED-ADDRESS can not be found since some servers that I tested does not return `XOR-MAPPED-ADDRESS.
Copyright 2023 Datong Sun (dndx@idndx.com)
Licensed under the Apache License, Version 2.0