使用boost asio枚举我的卡的ipv4和ipv6地址 [英] enumerating ipv4 and ipv6 address of my cards using boost asio
问题描述
我试图枚举我的PC上所有网卡(我有2张卡)的ipv4和ipv6地址.
I am trying to enumerate ipv4 and ipv6 addresses of all the network cards(I have 2 cards) my pc.
我正在使用以下代码来做到这一点.
I am using the following code to do that.
using boost::asio::ip::tcp;
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(boost::asio::ip::host_name(),"");
tcp::resolver::iterator it=resolver.resolve(query);
while(it!=tcp::resolver::iterator())
{
boost::asio::ip::address addr=(it++)->endpoint().address();
if(addr.is_v6())
{
std::cout<<"ipv6 address: ";
}
else
std::cout<<"ipv4 address: ";
std::cout<<addr.to_string()<<std::endl;
}
该代码显示正确的ipv4地址,但不显示ipv6.这是输出
The code displays correct ipv4 addresses but not ipv6. Here is the output
ipv6 address: ::1
ipv4 address: 192.168.10.200
ipv4 address: 192.168.10.236
我对ipv6知之甚少.当我列出有关使用ipconfig/all的网络接口的信息时,我看到实际的ipv6地址是
I have very minimum knowledge of ipv6. When I list the information about network interface using ipconfig/all I see that the actual ipv6 addresses are
fe80::226:5aff:fe14:5687%5
fe80::225:64ff:feb2:4f61%4
有人可以指导我如何列出ipv6地址. 谢谢.
Can someone please guide me how to list the ipv6 addresses. Thanks.
推荐答案
如果平台是Windows 7 SP1,则链接本地接口将被跳过,因为Windows将其标记为" SkipAsSource " getaddrinfo
不会返回它们,因此都不会增强.
If the platform is Windows 7 SP1 the link-local interfaces are being skipped as they are tagged "SkipAsSource" by Windows which means that getaddrinfo
will not return them and hence neither will Boost.
您可以尝试使用以下命令检查标志:
You can try to inspect the flag with the following command:
netsh int ipv6 show addresses level=verbose
Address fe80::e0:0:0:0%14 Parameters
---------------------------------------------------------
Interface Luid : Teredo Tunneling Pseudo-Interface
Scope Id : 0.14
Valid Lifetime : infinite
Preferred Lifetime : infinite
DAD State : Deprecated
Address Type : Other
Skip as Source : **true**
这篇关于使用boost asio枚举我的卡的ipv4和ipv6地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!