Linux under the query network IP several methods summary

  • 2020-05-30 21:42:58
  • OfStack

Linux query IP several methods summary

Curl plain text output:


curl icanhazip.com
curl ifconfig.me
curl curlmyip.com
curl ip.appspot.com
curl ipinfo.io/ip
curl ipecho.net/plain
curl www.trackip.net/i

Output in curl JSON format:


curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?json ( A little ugly )

Output in curl XML format:


curl ifconfig.me/all.xml

curl gets all IP details (excavator)


curl ifconfig.me/all

Use DYDNS (useful when you use DYDNS services)


curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"
 

Use Wget instead of Curl


wget http://ipecho.net/plain -O - -q ; echo
wget http://observebox.com/ip -O - -q ; echo

Use the host and dig commands

If so, you can also use the host and dig commands directly.


host -t a dartsclink.com | sed 's/.*has address //'
dig +short myip.opendns.com @resolver1.opendns.com

Example bash script:


#!/bin/bash
PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
echo $PUBLIC_IP

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: