54 lines
1.1 KiB
Objective-C
54 lines
1.1 KiB
Objective-C
//
|
|
// HttpdnsResult.m
|
|
// NewHttpDNS
|
|
//
|
|
// Created by xuyecan on 2024/5/15.
|
|
// Copyright © 2024 trustapp.com. All rights reserved.
|
|
//
|
|
|
|
#import "HttpdnsResult.h"
|
|
|
|
@implementation HttpdnsResult
|
|
|
|
- (BOOL)hasIpv4Address {
|
|
return self.ips.count > 0;
|
|
}
|
|
|
|
- (BOOL)hasIpv6Address {
|
|
return self.ipv6s.count > 0;
|
|
}
|
|
|
|
- (nullable NSString *)firstIpv4Address {
|
|
if (self.ips.count == 0) {
|
|
return nil;
|
|
}
|
|
return self.ips.firstObject;
|
|
}
|
|
|
|
- (nullable NSString *)firstIpv6Address {
|
|
if (self.ipv6s.count == 0) {
|
|
return nil;
|
|
}
|
|
return self.ipv6s.firstObject;
|
|
}
|
|
|
|
- (NSString *)description {
|
|
NSMutableString *result = [NSMutableString stringWithFormat:@"Host: %@", self.host];
|
|
|
|
if ([self hasIpv4Address]) {
|
|
[result appendFormat:@", ipv4 Addresses: %@", [self.ips componentsJoinedByString:@", "]];
|
|
} else {
|
|
[result appendString:@", ipv4 Addresses: None"];
|
|
}
|
|
|
|
if ([self hasIpv6Address]) {
|
|
[result appendFormat:@", ipv6 Addresses: %@", [self.ipv6s componentsJoinedByString:@", "]];
|
|
} else {
|
|
[result appendString:@", ipv6 Addresses: None"];
|
|
}
|
|
|
|
return [result copy];
|
|
}
|
|
|
|
@end
|