I'm using dig
utility to find public IP address.
The command I used is:
dig +short myip.opendns.com @resolver1.opendns.com
but I had problem since on some other computers it took so long, so I added a timeout after 5 seconds:
dig +short +time=5 +tries=1 myip.opendns.com @resolver1.opendns.com
and it fails on some as expected, but on some other computers it never finishes. All it does is hangs...
Any idea why and how can this be fixed to timeout after 5 seconds as expected ?
EDIT:
Already tried timeout
but it still hangs. I think it stucks while resolving DNS. For example, I can't ping www.google.com
, but can 172.217.20.4
.