enumhost.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Name: enumhost
  3. * Version: 0.2.0
  4. * Description: Enumerate the hosts associated with a hostname
  5. * Dependencies: bzbnet, bzbutil
  6. */
  7. #include "balzebub.h"
  8. using namespace bzbio;
  9. using namespace bzbterm;
  10. constexpr int VERSION_MAJOR = 0;
  11. constexpr int VERSION_MINOR = 2;
  12. constexpr int VERSION_PATCH = 0;
  13. const char* PROGNAME = "enumhost";
  14. void print_help_exit(int err = 0) {
  15. println("Usage: ", PROGNAME, " [ -h | --help ] | <filename>");
  16. println("Enumerate the hosts associated with the given hostname");
  17. println("-h | --help\tShow this help");
  18. exit(err);
  19. }
  20. void print_version_exit() {
  21. print(PROGNAME, " v");
  22. println(VERSION_MAJOR, ".", VERSION_MINOR, ".", VERSION_PATCH);
  23. println("This program is part of the Balzebub project.");
  24. exit(0);
  25. }
  26. int main(int argc, char const *argv[]) {
  27. if(argc < 2) {
  28. print_help_exit(1);
  29. }
  30. std::string arg(argv[1]);
  31. if(arg == "-v" || arg == "--version") {
  32. print_version_exit();
  33. }
  34. if(arg == "-h" || arg == "--help") {
  35. print_help_exit();
  36. }
  37. std::vector<std::string> addresses;
  38. try {
  39. addresses = bzbnet::get_host_list(arg);
  40. } catch(std::exception& e) {
  41. println("Unable to enumerate host list. ERROR:\n", e.what());
  42. }
  43. for(int i = 0; i < addresses.size(); ++i) {
  44. if(i % 2) {
  45. println(fg::white, addresses[i]);
  46. } else {
  47. println(fg::bright_white, addresses[i]);
  48. }
  49. }
  50. return 0;
  51. }