(ws) add a dnslookup sub-command, to get the ip address of a remote host

This commit is contained in:
Benjamin Sergeant 2020-01-22 21:11:48 -08:00
parent 99fe6ea493
commit 4c15964d43
6 changed files with 49 additions and 1 deletions

View File

@ -1,6 +1,10 @@
# Changelog # Changelog
All changes to this project will be documented in this file. All changes to this project will be documented in this file.
## [7.9.6] - 2020-01-22
(ws) add a dnslookup sub-command, to get the ip address of a remote host
## [7.9.5] - 2020-01-14 ## [7.9.5] - 2020-01-14
(windows) fix #144, get rid of stubbed/un-implemented windows schannel ssl backend (windows) fix #144, get rid of stubbed/un-implemented windows schannel ssl backend

View File

@ -6,4 +6,4 @@
#pragma once #pragma once
#define IX_WEBSOCKET_VERSION "7.9.5" #define IX_WEBSOCKET_VERSION "7.9.6"

View File

@ -65,6 +65,7 @@ add_executable(ws
ws_autobahn.cpp ws_autobahn.cpp
ws_proxy_server.cpp ws_proxy_server.cpp
ws_sentry_minidump_upload.cpp ws_sentry_minidump_upload.cpp
ws_dns_lookup.cpp
ws.cpp) ws.cpp)
target_link_libraries(ws ixsnake) target_link_libraries(ws ixsnake)

View File

@ -338,6 +338,9 @@ int main(int argc, char** argv)
minidumpApp->add_option("--key", key, "Sentry Key")->required(); minidumpApp->add_option("--key", key, "Sentry Key")->required();
minidumpApp->add_flag("-v", verbose, "Verbose"); minidumpApp->add_flag("-v", verbose, "Verbose");
CLI::App* dnsLookupApp = app.add_subcommand("dnslookup", "DNS lookup");
dnsLookupApp->add_option("host", hostname, "Hostname")->required();
CLI11_PARSE(app, argc, argv); CLI11_PARSE(app, argc, argv);
// pid file handling // pid file handling
@ -509,6 +512,10 @@ int main(int argc, char** argv)
{ {
ret = ix::ws_sentry_minidump_upload(metadata, minidump, project, key, verbose); ret = ix::ws_sentry_minidump_upload(metadata, minidump, project, key, verbose);
} }
else if (app.got_subcommand("dnslookup"))
{
ret = ix::ws_dns_lookup(hostname);
}
else if (version) else if (version)
{ {
spdlog::info("ws {}", ix::userAgent()); spdlog::info("ws {}", ix::userAgent());

View File

@ -163,4 +163,6 @@ namespace ix
const std::string& project, const std::string& project,
const std::string& key, const std::string& key,
bool verbose); bool verbose);
int ws_dns_lookup(const std::string& hostname);
} // namespace ix } // namespace ix

34
ws/ws_dns_lookup.cpp Normal file
View 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