r/tinycode • u/trashbox • Jul 10 '11
Outside IP one-liner.
curl http://checkip.dyndns.com/ 2>/dev/null | sed 's/.*: \(.*\)<\/b.*/\1/'
18
u/prototrout Jul 10 '11 edited Jul 10 '11
curl http://whatismyip.org/Or if you prefer:
curl 11346145062
u/terremoto Jul 10 '11 edited Jul 10 '11
Better:wget -O- http://automation.whatismyip.com/n09230945.asp
Seehttp://www.whatismyip.com/faq/automation.aspNevermind, I thought the OP was using whatismyip.com.
1
2
Jul 10 '11
How is that any better?
1
u/terremoto Jul 10 '11
Visit the URL and I think it will be self explanatory -- you don't have to parse out the IP address.
1
0
3
5
3
Jul 10 '11
tracepath -n 192.88.99.1 | awk '/2: / { print $2; exit }'3
u/terremoto Jul 11 '11 edited Jul 11 '11
That won't always return the correct address depending on your network topology.
EDIT: I got bored and decided to make a version of this that will match the first non-reserved address; a monstrosity follows (yes, the IP regex could be condensed. EDIT 2 -- Okay, I condensed the regex.):
tracepath -n 192.88.99.1 | grep -vm1 "\(192\.168\|169\.254\|172\.\(1[6-9]\|2[0-9]\|3[01]\)\|10\.[0-9]\+\)\(\.[0-9]\+\)\{2\}" | grep -o "\([0-9]\+\.\)\{3\}[0-9]\+"EDIT 3 -- For traceroute:
traceroute 192.88.99.1 | grep -vm1 "\(192\.168\|169\.254\|172\.\(1[6-9]\|2[0-9]\|3[01]\)\|10\.[0-9]\+\)\(\.[0-9]\+\)\{2\}\|192\.88\.99\.1" | grep -o "\([0-9]\+\.\)\{3\}[0-9]\+"
2
u/obsa Jul 11 '11
The thing that annoys me most about that particular service is the "Current IP Address" prefix. Why is that even necessary?
/complaining about free stuff
14
u/infinitus_ Jul 10 '11