# ipv4 && ipv6

## 查询本机外网IP地址

```shellscript
# 查询本机外网IPv4地址
curl 4.ipw.cn

# 查询本机外网IPv6地址
curl 6.ipw.cn

# 测试网络是IPv4还是IPv6访问优先(访问IPv4/IPv6双栈站点,如果返回IPv6地址,则IPv6访问优先)
curl test.ipw.cn

浏览器访问

访问 http://[2402:4e00:1013:e500:0:9671:f018:4947]/ ,会返回本机 IPv6 IP地址。

IPv6地址示例

如果有端口,在 IP 地址后面添加端口,比如:
http://[2402:4e00:1013:e500:0:9671:f018:4947]:80/

Ping IPv6 地址

~$ ping6 6.ipw.cn
PING6(56=40+8+8 bytes) 1111:1111:30c0:9556:b807:e464:1111:1111 --> 2402:4e00:1013:e500:0:9671:f018:4947
16 bytes from 2402:4e00:1013:e500:0:9671:f018:4947, icmp_seq=0 hlim=52 time=8.748 ms
16 bytes from 2402:4e00:1013:e500:0:9671:f018:4947, icmp_seq=1 hlim=52 time=8.715 ms

终端 CURL 访问

在 Linux 下需要增加 -g 参数:

-g, --globoff
    这个选项关闭"URL通配符解析器"。设置此选项后,可以指定包含{}[]字符的URL而不会被curl本身解释。
curl -g http://[2402:4e00:1013:e500:0:9671:f018:4947]/

curl 指定 IPv6 或 IPv4 访问

curl -4 test.ipw.cn
106.224.145.147

curl -6 test.ipw.cn
2408:824c:200::2b8b:336f:cc9c

telnet ipv6 地址

telnet -6 2402:4e00:1013:e500:0:940e:29d7:3443 80
Trying 2402:4e00:1013:e500:0:940e:29d7:3443...
Connected to 2402:4e00:1013:e500:0:940e:29d7:3443.
Escape character is '^]'.