【发布时间】:2017-07-14 10:51:32
【问题描述】:
我正在尝试将我的互联网 IP 地址保存到 shell 中的变量中。
我试过了
ip=`host 'localhost' | awk '{print $4}'`
但那会返回
127.0.0.1
如何将互联网 IP 地址保存到 shell 中的变量中?
【问题讨论】:
-
什么IP?您的 WAN(外部)IP?
-
我本地互联网的 ip,而不是 77.somethingother
-
但是 192.somethingelse
-
只有本地wifi
-
试试
ifconfig | grep inet | cut -d ' ' -f 2 | cut -d ':' -f 2。