Get public ip

From KCLUG Wiki

Jump to: navigation, search

From Bash and Command line One-Liners

Noreply.org has been around for a while, and their site is one of many that replies with your public address. Use grep and sed to cut the ip address out. This would be useful if you are behind NAT, or otherwise do not know the address from which your traffic emerges onto the publicly routable internet.

curl -s http://www.noreply.org | grep Hello | sed -e 's/.*\[//' -e 's/\].*//'

Use this in scripts as follows:

#! /bin/bash

IP=`curl -s http://www.noreply.org | grep Hello | sed -e 's/.*\[//' -e 's/\].*//'`
echo Why hello there.  Your IP is ${IP}
Personal tools