From 9d7807b25ccdb07ae075c9e1f52696881e0e2707 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Wed, 22 Jan 2020 21:11:48 -0800 Subject: [PATCH] (ws) add a dnslookup sub-command, to get the ip address of a remote host --- docs/CHANGELOG.md | 4 ++++ ixwebsocket/IXWebSocketVersion.h | 2 +- ws/CMakeLists.txt | 1 + ws/ws.cpp | 7 +++++++ ws/ws.h | 2 ++ ws/ws_dns_lookup.cpp | 34 ++++++++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 ws/ws_dns_lookup.cpp diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 151505f5..7fd3441b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog 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 (windows) fix #144, get rid of stubbed/un-implemented windows schannel ssl backend diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index ba362f57..842ae2ac 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "7.9.5" +#define IX_WEBSOCKET_VERSION "7.9.6" diff --git a/ws/CMakeLists.txt b/ws/CMakeLists.txt index affa3b2a..c777a6de 100644 --- a/ws/CMakeLists.txt +++ b/ws/CMakeLists.txt @@ -65,6 +65,7 @@ add_executable(ws ws_autobahn.cpp ws_proxy_server.cpp ws_sentry_minidump_upload.cpp + ws_dns_lookup.cpp ws.cpp) target_link_libraries(ws ixsnake) diff --git a/ws/ws.cpp b/ws/ws.cpp index 18b3f336..03a4495a 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -338,6 +338,9 @@ int main(int argc, char** argv) minidumpApp->add_option("--key", key, "Sentry Key")->required(); 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); // pid file handling @@ -509,6 +512,10 @@ int main(int argc, char** argv) { 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) { spdlog::info("ws {}", ix::userAgent()); diff --git a/ws/ws.h b/ws/ws.h index adfc678a..354cb7f1 100644 --- a/ws/ws.h +++ b/ws/ws.h @@ -163,4 +163,6 @@ namespace ix const std::string& project, const std::string& key, bool verbose); + + int ws_dns_lookup(const std::string& hostname); } // namespace ix diff --git a/ws/ws_dns_lookup.cpp b/ws/ws_dns_lookup.cpp new file mode 100644 index 00000000..b97e496f --- /dev/null +++ b/ws/ws_dns_lookup.cpp @@ -0,0 +1,34 @@ +/* + * ws_dns_lookup.cpp + * Author: Benjamin Sergeant + * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include + + +namespace ix +{ + int ws_dns_lookup(const std::string& hostname) + { + auto dnsLookup = std::make_shared(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