https://github.com/snawoot/extip
Go package which retrieves external address IP using STUN servers
https://github.com/snawoot/extip
external-ip ip-address ip-address-lookup stun stun-client
Last synced: 16 days ago
JSON representation
Go package which retrieves external address IP using STUN servers
- Host: GitHub
- URL: https://github.com/snawoot/extip
- Owner: Snawoot
- License: mit
- Created: 2020-06-05T14:51:18.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-08-11T10:56:47.000Z (over 1 year ago)
- Last Synced: 2025-03-27T13:51:22.330Z (about 1 month ago)
- Topics: external-ip, ip-address, ip-address-lookup, stun, stun-client
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# extip
Go package which retrieves external IP address using STUN servers
---
:heart: :heart: :heart:
You can say thanks to the author by donations to these wallets:
- ETH: `0xB71250010e8beC90C5f9ddF408251eBA9dD7320e`
- BTC:
- Legacy: `1N89PRvG1CSsUk9sxKwBwudN6TjTPQ1N8a`
- Segwit: `bc1qc0hcyxc000qf0ketv4r44ld7dlgmmu73rtlntw`---
## Usage
Example:
```go
package mainimport (
"fmt"
"github.com/Snawoot/extip"
"context"
"os"
"time"
)func main() {
ctx, _ := context.WithTimeout(context.Background(), 3 * time.Second)
ip, err := extip.QueryMultipleServers(ctx, nil, 2, false)
if err != nil {
switch res := err.(type) {
case extip.InconclusiveResult:
fmt.Fprintf(os.Stderr, "Inconclusive result:\n")
fmt.Fprintf(os.Stderr, "Required quorum = %v\n", res.Quorum)
for k, v := range res.Results {
fmt.Fprintf(os.Stderr, "Server %s responded: %s\n", k, v)
}
for k, v := range res.Errors {
fmt.Fprintf(os.Stderr, "Server %s failed: %v\n", k, v)
}
default:
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
}
return
}
fmt.Println(ip)
}
```See GoDoc and sources for more details.