以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 检测本机ipv6地址 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=187714) |
-- 作者:ycs5801 -- 发布时间:2023/8/6 15:25:00 -- 检测本机ipv6地址 Dim IPAdress As System.Net.IPAddress Dim HostName As String HostName = System.Net.Dns.GetHostName \'获得本机的机器名 Dim l As Integer = System.Net.Dns.GetHostByName(HostName).AddressList.Length Dim s As String = "" For i As Integer=0 To l-1 IPAdress = System.Net.Dns.GetHostByName(HostName).AddressList.getValue(i) \'获得本机的IP s &= IPAdress.Tostring & "," Next msgbox(s.trim(",")) 以上论坛找到的方法,可以检测出本机的ip4地址,现在想检测到本机的ipv6地址需要怎样改?有线网络连接的。 |
-- 作者:有点蓝 -- 发布时间:2023/8/6 21:21:00 -- 代码默认就会返回对应的ipv4地址还是ipv6地址,前提是确实设置并用到了ipv6地址。如果要把ipv4转换为ipv6可以这样 s &= IPAdress.MapToIPv6.Tostring & "," https://learn.microsoft.com/zh-cn/dotnet/api/system.net.ipaddress.maptoipv6?view=netframework-4.5&redirectedfrom=MSDN#System_Net_IPAddress_MapToIPv6
|
-- 作者:ycs5801 -- 发布时间:2023/8/6 23:32:00 -- 这个只是把ipv4地址转换成了ipv6地址,并不是真正的ipv6地址啊? |
-- 作者:有点蓝 -- 发布时间:2023/8/7 8:45:00 -- 这种应该是【内嵌IPv4地址表示法】:https://baike.baidu.com/item/IPv6/172297?fr=ge_ala,如果要显示为其它格式,自行百度吧,我也没有什么研究 |
-- 作者:chen37280600 -- 发布时间:2023/8/7 9:42:00 -- 狐表以外的技术问题,问chatgpt更快: 稍微改一下成狐表用的代码: Dim hostName As String = System.Net.Dns.GetHostName() Dim ipAddresses() As System.Net.IPAddress = System.Net.Dns.GetHostAddresses(hostName) For Each ipAddress As System.Net.IPAddress In ipAddresses If ipAddress.AddressFamily = System.Net.Sockets.AddressFamily.InterNetworkV6 Then Output.Show("IPv6 Address: " & ipAddress.ToString()) End If Next 执行结果: IPv6 Address: fe80::1f98:fe2a:180b:eb61%6 |