主机参考: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;
这几篇文章你可能也喜欢:
- Linux librtmp可以发送加密
- 如何使用hexedit加密Linux数据(Linux加密字符串)
- Linux命令安装播放什么? (Linux安装命令)
- 如何有效操作CHMOD Linux命令
- Linux命令安装(Linux的核心部分)的核心是什么?
本文由主机参考刊发,转载请注明:linux如何读取公网(linux命令行如何查看公网ip) https://zhujicankao.com/120393.html
评论前必须登录!
注册