我知道遠程機器的名稱,這臺機器是在同一個網絡上。從機器名稱查找機器IP地址
如果我從命令提示符ping那臺機器,我也會得到IP信息。
C:\Users\anikumar>ping neemqx01g
Pinging neemqx01g.efi.internal [10.210.98.194] with 32 bytes of data:
Reply from 10.210.98.194: bytes=32 time=2ms TTL=128
Reply from 10.210.98.194: bytes=32 time<1ms TTL=128
Reply from 10.210.98.194: bytes=32 time<1ms TTL=128
Reply from 10.210.98.194: bytes=32 time<1ms TTL=128
Ping statistics for 10.210.98.194:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 2ms, Average = 0ms
如何在wxWidgets中以編程方式實現或獲取IP地址?
答案:
C函數:
const wxString GetIPbyName(const wxString& name)
{
struct hostent* pHostInfo;
pHostInfo = gethostbyname(name.c_str());
in_addr * address = (in_addr *)pHostInfo->h_addr;
std::string ip_address = inet_ntoa(*address);
return ip_address;
}
wxWidgets的:
wxIPV4address ipv4;
ipv4.Hostname(m_currentServer);
wxString m_currentServer = ipv4.IPAddress();
我不是如何在多個活動網卡的情況下行爲。
見http://stackoverflow.com/questions/5486113/boost-asio-how-to-turn-url-into-ip-adress –
@YamMarcovic:該OP不問的URI,也無法左右升壓.ASIO。 –
我投票結束作爲資源請求。 – NathanOliver