2
如何使用POCO查找我的公共IP?使用POCO查找公開IP
由their Network presentation 6頁的啓發,我試過如下:
#include "Poco/Net/DNS.h"
#include <iostream>
using Poco::Net::DNS;
using Poco::Net::HostEntry;
int main(int argc, char** argv)
{
const HostEntry& entry = DNS::thisHost();
std::cout << "Canonical Name: " << entry.name() << std::endl;
const HostEntry::AliasList& aliases = entry.aliases();
HostEntry::AliasList::const_iterator alias_it = aliases.begin();
for (; alias_it != aliases.end(); ++alias_it)
std::cout << "Alias: " << *alias_it << std::endl;
const HostEntry::AddressList& addrs = entry.addresses();
HostEntry::AddressList::const_iterator addr_it = addrs.begin();
for (; addr_it != addrs.end(); ++addr_it)
std::cout << "Address: " << addr_it->toString() << std::endl;
return 0;
}
然而,這回兩個地址:一個IPv6鏈路本地(FE80:...)和一個專用LAN的IPv4(10.0 ...)。它沒有返回我的公共IP。
可以這樣做嗎?