Ok, so I have a curl/awk one-liner that can get me my ip in shell scripts that uses checkip.dyndns.org. It's super simple because the results are super simple from checkip.
Anyone want to take a stab at this for google's result page?
Anyone want to take a stab at this for google's result page?
curl --silent 'http://www.google.com/search?q=what+is+my+ip' | sed 's/.*Client IP address: //;s/).*//;q'
Google responds with HTTP error 403 (Forbidden), but it just so happens the client IP address is in the error page. curl icanhazip.com http://myip.dnsomatic.com
http://whatismyip.org #!/bin/sh
# example from `who - u`:
#nick pts/0 2011-07-20 20:44 . 7856 (xxxxxxx.xxxxxxxx.internode.on.net)
who -u | awk 'BEGIN {FS="[p.]"} /internode/ {print gensub("-",".","g",$6); exit}'
You might need to play around with gensub(...). Sometime `who` reports the IP as xxx-xxx-xxx-xxx and sometimes as xxx.xxx.xxx.xxx wget -Ufoo -qO- 'http://www.google.com/search?q=ip' |
sed -n '/.*Your public IP address is [^0-9]*\([0-9.]*\).*/{s//\1/p;q;}'