There are actually some public services that you can test your public IP easily, for example, ipinfo.io for global users and ipip.net for Chinese users.

ipinfo.io

1
curl ipinfo.io

You will get a response in JSON, including your current city, region, country, organization, etc.

1
2
3
4
5
6
7
8
9
{
"ip": "12.34.56.78",
"hostname": "No Hostname",
"city": "",
"region": "",
"country": "US",
"loc": "37.7510,-97.8220",
"org": "AS7018 AT&T Services, Inc."
}

ipip.net

1
curl myip.ipip.net

You will get a plain text response, including your current city, country, ISP, etc.

1
当前 IP:16.221.25.51 来自于:中国 上海 上海电信