单行检索外部IP地址

Ste*_*ett 0 scripting linux ip-address

可能的重复:
在 shell 脚本中查找公共 IP 地址

为了在脚本中使用,能够做到这一点会很方便:

IP=`....something ....`
echo ...$IP... >> configfile
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我正在寻找网络上看到的 IP 地址。Ubuntu,如果它有所作为。很高兴安装一两个软件包。

Ste*_*han 5

IP=`curl ifconfig.me`

[stephan@nemesis] ~ $ curl ifconfig.me
173.13.169.18
Run Code Online (Sandbox Code Playgroud)

瞧。:)

(2020 年 9 月编辑)

我现在通常使用icanhazip.com。不过,您可能需要切掉换行符:

curl -s icanhazip.com | tr -d '\n'