How to query the external network IP address on mac/linux

Query ip address, this is a simple topic!
However, have you ever encountered a situation where the external network address cannot be queried?
Let's take a look together

Note that the mac/linux system is mentioned here. If it is a windows system, you can go out.

basic version

This is the basic version of ip query, which is also applicable to most scenarios.
In the terminal, enter ifconfig, and you can see your network card information.
This is my local ip. You can see the external network IP in the picture below
image.png

Then, here comes the exception. If what you want to see is a computer room (or a server extended from a virtual machine),
you ifconfigwill get the result shown in the figure below, and you will only be able to see the internal network IP, but not the Is there a problem with the external network IP
image.png
? At this point, how to check the external network IP? Is it the advanced version?

advanced version

There are many methods, and I personally think that this one is extremely simple and practical.
Use the following command, and you will get the external network IP you want

curl ifconfig.me/all

insert image description here

insert image description here

Of course, other commands are also available, but the output form is different, for example, the following

  • The output is json, the following three are all available
curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?json
  • output as XML
curl ipinfo.io/json

Summarize

Regardless of the basic version or the advanced version, they are all simple commands, which can be used flexibly to get twice the result with half the effort

Guess you like

Origin blog.csdn.net/Long861774/article/details/127474978