#include <xtd/net/sockets/socket>
#include <xtd/net/dns>
#include <xtd/net/ip_address>
#include <xtd/text/string_builder>
#include <xtd/console>
#include <xtd/startup>
#include <regex>
 
 
class test_ip_address {
public:
    
    
    
    
    auto rex = std::regex {R"(^[a-zA-Z]\w{1,39}$)"};
    
      
      
      server = dns::get_host_name();
      console::write_line("Using current host: {}", server);
    } else {
      server = args[0];
      if (!regex_match(server.chars(), rex)) {
        console::write_line("Input string format not allowed.");
        return;
      }
    }
    
    
    ip_addresses(server.to_string());
    
    
    ip_address_additional_info();
  }
  
private:
  static void ip_addresses(const string& server) {
    try {
      
      auto heserver = dns::get_host_entry(server);
      
      
      for (auto cur_add : heserver.address_list()) {
        
        
        
        console::write_line("address_family: {}", cur_add.address_family());
        
        
        if (cur_add.address_family() == address_family::inter_network_v6)
          console::write_line("scope id: {}", cur_add.scope_id());
          
          
        
        
        
        console::write_line("address: {}", cur_add);
        
        
        console::write("address_bytes: ");
        
        auto bytes = cur_add.get_address_bytes();
        for (size_t i = 0; i < bytes.size(); i++)
          console::write(bytes[i]);
        console::write_line("\r\n");
      }
      console::write_line("[do_resolve] exception: {}", e);
    }
  }
  
  
  static void ip_address_additional_info() {
    try {
      
      
      console::write_line("\r\nos_supports_ip_v4: {}", socket::os_supports_ip_v4());
      console::write_line("os_supports_ip_v6: {}", socket::os_supports_ip_v6());
      
      if (socket::os_supports_ip_v6()) {
        
        
        console::write_line("\r\nip_v6_any: {}", ip_address::ip_v6_any);
        
        
        console::write_line("ip_v6_loopback: {}", ip_address::ip_v6_loopback);
        
        
        console::write_line("ip_v6_none: {}", ip_address::ip_v6_none);
        
        console::write_line("is_loopback(ip_v6_loopback): {}", ip_address::is_loopback(ip_address::ip_v6_loopback));
      }
      console::write_line("is_loopback(loopback):{}", ip_address::is_loopback(ip_address::loopback));
      console::write_line("[ip_addresses] exception: {}", e);
    }
  }
};
 
 
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:71
 
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::collections::generic::list::...
Definition list.hpp:364
 
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.hpp:18
 
Represents a mutable string of characters. This class cannot be inherited.
Definition basic_string_builder.hpp:35
 
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:175
 
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:15
 
The xtd::net::sockets namespace provides a managed implementation of the Berkeley Sockets interface f...
Definition address_family.hpp:16
 
The xtd::net namespace provides a simple programming interface for many of the protocols used on netw...
Definition cookie_exception.hpp:11
 
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
 
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10