(ws) add a dnslookup sub-command, to get the ip address of a remote host
This commit is contained in:
34
ws/ws_dns_lookup.cpp
Normal file
34
ws/ws_dns_lookup.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ws_dns_lookup.cpp
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <atomic>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <sstream>
|
||||
#include <ixwebsocket/IXNetSystem.h>
|
||||
#include <ixwebsocket/IXDNSLookup.h>
|
||||
|
||||
|
||||
namespace ix
|
||||
{
|
||||
int ws_dns_lookup(const std::string& hostname)
|
||||
{
|
||||
auto dnsLookup = std::make_shared<DNSLookup>(hostname, 80);
|
||||
|
||||
std::string errMsg;
|
||||
struct addrinfo* res;
|
||||
|
||||
res = dnsLookup->resolve(errMsg, [] { return false; });
|
||||
|
||||
auto addr = res->ai_addr;
|
||||
|
||||
char str[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &addr, str, INET_ADDRSTRLEN);
|
||||
|
||||
spdlog::info("host: {} ip: {}", hostname, str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // namespace ix
|
Reference in New Issue
Block a user