使用curl和awk获取本地服务器的外网IP地址

[root@VM-0-17-centos ~]# curl myip.ipip.net | awk '{print $2}'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    67  100    67    0     0    848      0 --:--:-- --:--:-- --:--:--   858
IP:1.*.*.*
[root@VM-0-17-centos ~]# 

我只想拿到IP地址,但是会打印出耗时这块,不知道为什么,没有想明白,系统是centos7.8.

你需要加个参数 -s 隐藏耗时

curl -s myip.ipip.net | awk '{print $2}'

试试这个:
curl ip.sb
有用的记得点击一下采纳谢谢

curl 后面得加上-s,即指定Silent模式,不输出耗时等信息

curl -s  myip.ipip.net | awk '{print $2}'