在Linux终端中查看公有IP的方法详解 |
本文标签:Linux,IP 首先pps下一般的查看IP的命令: 如何在 Linux 终端中知道你的公有 IP 在本文中我将会介绍在几种在 Linux 终端中查看你的公有 IP 地址的方法 。这对普通用户来说并无意义,但 Linux 服务器(无GUI或者作为只能使用基本工具的用户登录时)会很有用 。无论如何,从 Linux 终端中获取公有 IP 在各种方面都很意义,说不定某一天就能用得着 。 以下是我们主要使用的两个命令,curl 和 wget 。你可以换着用 。 Curl 纯文本格式输出: 复制代码 代码如下:curl icanhazip.com curl ifconfig.me curl curlmyip.com curl ip.appspot.com curl ipinfo.io/ip curl ipecho.net/plain curl www.trackip.net/i curl JSON格式输出: 复制代码 代码如下:curl ipinfo.io/json curl ifconfig.me/all.json curl www.trackip.net/ip?json curl XML格式输出: 复制代码 代码如下:curl ifconfig.me/all.xml curl 得到所有IP细节 (挖掘机) curl ifconfig.me/all 使用 DYDNS (当你使用 DYDNS 服务时有用) 复制代码 代码如下:curl -s http://checkip.dyndns.org | sed s/.*Current IP Address: \([0-9\.]*\).*/\1/g curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+" 使用 Wget 代替 Curl 复制代码 代码如下:wget http://ipecho.net/plain -O - -q ; echo wget http://observebox.com/ip -O - -q ; echo 使用 host 和 dig 命令 如果有的话,你也可以直接使用 host 和 dig 命令 。 复制代码 代码如下:host -t a dartsclink.com | sed s/.*has address // dig +short myip.opendns.com @resolver1.opendns.com bash 脚本示例: 复制代码 代码如下:#!/bin/bash PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo` echo $PUBLIC_IP 简单易用 。 我实际上是在写一个用于记录每日我的路由器中所有 IP 变化并保存到一个文件的脚本 。我在搜索过程中找到了这些很好用的命令 。希望某天它能帮到其他人 。 |