code: public List<InetAddress> getSystemDNSServers() {
  
          List<InetAddress> dnsServers = new ArrayList<InetAddress>();
          ResolverConfig resolverConfig = new ResolverConfig();
  
          try {
              for(String dnsHostIp : resolverConfig.servers()) {
                  if(dnsHostIp.equals("")) continue;
                  dnsServers.add(InetAddress.getByName(dnsHostIp));
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
          return dnsServers;
      }
docs: Get System DNS Servers
  @return A list of InetAddress objects contains the system's configured DNS servers