主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情! |
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作 |
在Linux下读取公网IP地址
要获取Linux计算机的公共IP地址,可以使用以下方法:
使用卷曲命令:
& ltcode class = & quot壳牌& quot& gtcurl ifconfig.me & lt/code & gt;使用wget命令:
& ltcode class = & quot壳牌& quot& gtwget-qO-https://ifconfig . me & lt;/code & gt;使用dig命令:
& ltcode class = & quot壳牌& quot& gtdig+short myip.opendns.com @ resolver 1 . opendns . com & lt;/code & gt;使用ipify命令:
& ltcode class = & quot壳牌& quot& gtipify & lt/code & gt;将结果保存在变量中:
要将获得的公共IP地址保存在变量中,可以使用以下语法:
& ltcode class = & quot壳牌& quot& gtpublic _ IP = $(curl ifconfig . me)& lt;/code & gt;示例:
获取公共IP地址并将其打印到终端:
& ltcode class = & quot壳牌& quot& gtcurl ifconfig.me & lt/code & gt;获取公共网络的IP地址,并将其保存在变量中:
& ltcode class = & quot壳牌& quot& gtpublic _ IP = $(curl ifconfig . me)echo $ public _ IP & lt;/code & gt;
这几篇文章你可能也喜欢:
- 如何优化Kafka消费者绩效(Kafka消费者如何消耗数据)
- 如何将文件移至Linux上的指定目录? (Linux将文件移至另一个目录命令)
- 如何使用LNMP体系结构(LNMP调整)优化数据库查询
- 如果我的Linux Crond任务延迟了怎么办?
- 如何在Laravel(Laravel数据库连接池)中配置数据库连接
本文由主机参考刊发,转载请注明:linux如何读取公网(linux命令行如何查看公网ip) https://zhujicankao.com/120393.html
评论前必须登录!
注册