5 ms·
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 f
by noonespecial 15y ago
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?
- fjarlq 15y agoThis works, but only accidentally: 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.
- gizzlon 15y agohaha, nice one
- deleted 15y ago[deleted]
- nodata 15y agoOr use https://ip.appspot.com/ https://ip.appspot.com/
- a3_nm 15y agoEven simpler: curl icanhazip.com
- bostonvaulter2 15y agoI prefer 'curl ifconfig.me'
- ralph 15y agoOne way: 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;}'
- Nick_C 15y agoIf your use-case is from ssh'ing in a remote box, this may be simpler: #!/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