Categories
Workflow

Get your public ip address via the Mac Terminal and paste it

No browser needs to be opened. No text needs to be copied. Just run a command and paste your public ip where needed.

The following command run from the Terminal gets your public ip address and copies it to the clipboard of your Mac:

curl -s ifconfig.me | pbcopy

I tend to use aliases or create functions in my .zshrc file. If you are already using Z shell you can perform the following tasks to make it work:

vim ~/.zshrc

Paste this function into the file:

function publicip() {
( curl -s ifconfig.me | pbcopy )
( echo 'Public IP copied to clipboard!' )
}

Restart your Mac Terminal or run:

source ~/.zshrc

Now test your function by running:

publicip

You can now paste your public IP address anywhere!

Leave a Reply

Your email address will not be published. Required fields are marked *