App-dnsq
view release on metacpan or search on metacpan
IMPROVEMENTS.md view on Meta::CPAN
- Single source of truth for configuration values
#### DNSQuery::Validator
- Extracted all validation logic from multiple modules
- Provides reusable validation functions:
- `validate_domain()` - RFC 1035 compliant domain validation
- `validate_ip()` - IPv4 and IPv6 address validation
- `validate_query_type()` - DNS query type validation
- `validate_query_class()` - DNS query class validation
- `validate_port()` - Network port validation
- `validate_timeout()` - Timeout value validation
- `validate_retries()` - Retry count validation
- `validate_file_path()` - Batch file validation
- Includes comprehensive POD documentation
#### DNSQuery::Cache
- New dedicated cache module with advanced features
- Replaces simple hash-based cache in Resolver.pm
### Code Deduplication in Batch.pm
- **Before**: `_process_sequential()` and `_process_parallel()` had significant code duplication
IMPROVEMENTS.md view on Meta::CPAN
#### IP Address Validation
- IPv4: Octet range validation (0-255)
- IPv6: Basic structure and character validation
- Handles both address families
#### Query Type Validation
- Validates against known DNS record types
- Case-insensitive matching
- Clear error messages for invalid types
#### Port and Timeout Validation
- Range checking (ports: 1-65535)
- Type checking (numeric values only)
- Minimum value enforcement
### Better Error Messages
- Specific error messages for each validation failure
- Consistent error format across all modules
- Line number reporting in batch mode
## 4. Testing
[](bin/dnsq)
A full-featured dig-like DNS query tool written in Perl with JSON output, TCP/UDP support, trace mode, and batch processing.
## Features
- **Multiple Output Formats**: Full dig-like, short (answers only), or JSON
- **Protocol Support**: TCP and UDP
- **Custom DNS Server**: Query any DNS server with custom port
- **Timeout & Retries**: Configurable timeout and retry settings with exponential backoff
- **Batch Mode**: Process multiple queries from a file with parallel processing
- **Trace Mode**: Follow DNS delegation path from root servers
- **Interactive Mode**: Interactive shell with ASCII art banner and statistics
- **DNSSEC Support**: Request and display DNSSEC records
- **Smart Caching**: TTL-aware cache with optional disk persistence
- **Statistics Tracking**: Monitor query performance and cache hit rates
- **Progress Indicators**: Real-time progress for batch operations
- **Input Validation**: Comprehensive validation for domains, IPs, and query types
## Installation
lib/DNSQuery/Validator.pm view on Meta::CPAN
Validates a timeout value in seconds.
Returns: (1, undef) on success, (0, error_message) on failure.
=cut
sub validate_timeout {
my ($timeout) = @_;
return (0, "Timeout is required")
unless defined $timeout;
return (0, "Timeout must be numeric")
unless $timeout =~ /^\d+$/;
return (0, "Timeout must be at least $MIN_TIMEOUT second(s)")
if $timeout < $MIN_TIMEOUT;
return (1, undef);
}
=head2 validate_retries($retries)
Validates a retry count.
Returns: (1, undef) on success, (0, error_message) on failure.
t/validator.t view on Meta::CPAN
ok(!$valid, 'Port 0 rejected');
($valid, $error) = validate_port(65536);
ok(!$valid, 'Port > 65535 rejected');
($valid, $error) = validate_port('abc');
ok(!$valid, 'Non-numeric port rejected');
};
# Test timeout validation
subtest 'Timeout validation' => sub {
my ($valid, $error);
($valid, $error) = validate_timeout(5);
ok($valid, 'Valid timeout: 5');
($valid, $error) = validate_timeout(1);
ok($valid, 'Valid timeout: 1');
($valid, $error) = validate_timeout(0);
ok(!$valid, 'Timeout 0 rejected');
($valid, $error) = validate_timeout(-1);
ok(!$valid, 'Negative timeout rejected');
};
# Test constants
subtest 'Constants' => sub {
ok($DNSQuery::Constants::VALID_QUERY_TYPES{A}, 'A type exists in constants');
ok($DNSQuery::Constants::VALID_QUERY_TYPES{AAAA}, 'AAAA type exists in constants');
ok($DNSQuery::Constants::VALID_QUERY_TYPES{MX}, 'MX type exists in constants');
( run in 0.518 second using v1.01-cache-2.11-cpan-bbdf54b448f )