←back to thread

224 points gurjeet | 1 comments | | HN request time: 0.21s | source
1. Snawoot ◴[] No.26636445[source]
I had some auto-tests for VPN app which were relying on similar web-service to check own IP address. One day service become unavailable and autotests got broken. IIRC it was (https://canihazip.com/s)

I decided to solve this task in a fast and reliable fashion, so I made a tool which discovers own IP address using major public STUN servers: https://github.com/Snawoot/myip

Program issues parallel queries to public STUN servers to determine public IP address and returns result as soon as quorum of matching responses reached.

Works fast and reliable, especially compared to services requiring HTTPS:

  user@dt1:~> time curl https://api.ipify.org
  45.152.165.44
  real 0m2,515s
  user 0m0,030s
  sys 0m0,019s
  
  
  user@dt1:~> time curl ifconfig.co/
  45.152.165.44
  
  real 0m0,131s
  user 0m0,011s
  sys 0m0,008s
  
  
  user@dt1:~> time myip
  45.152.165.44
  
  real 0m0,084s
  user 0m0,012s
  sys 0m0,012s