(ws) add a dnslookup sub-command, to get the ip address of a remote host
This commit is contained in:
		| @@ -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 | ||||||
|   | |||||||
| @@ -6,4 +6,4 @@ | |||||||
|  |  | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #define IX_WEBSOCKET_VERSION "7.9.5" | #define IX_WEBSOCKET_VERSION "7.9.6" | ||||||
|   | |||||||
| @@ -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) | ||||||
|   | |||||||
| @@ -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()); | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								ws/ws.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								ws/ws.h
									
									
									
									
									
								
							| @@ -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
									
								
							
							
						
						
									
										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