How to get IP address without curl

In case you don’t want to install curl via apt get curl
on alpine, debian or ubuntu operating system, you can use netcat instead which is preinstalled.
With curl, you could use:
curl https://ifconfig.me/
But using printf
, nc
and tail
you can get the same result:
printf "GET / HTTP/1.1\r\nHost: ifconfig.me\r\nUser-Agent: curl/7.64.1\r\nAccept: */*\r\n\r\n" | nc ifconfig.me 80 | tail -n1
This can happen f.e. if you have access to the user account, but you don’t have root access via sudo.