域名解析

#include 
#include 
#include 
#include 
/// 解析域名
- (NSString *)resolveDomain:(NSString *)domain {
    struct hostent *hs;
    struct sockaddr_in server;
    if ((hs = gethostbyname([domain UTF8String])) != NULL) {
        server.sin_addr = *((struct in_addr*)hs->h_addr_list[0]);
        NSString *ip = [NSString stringWithUTF8String:inet_ntoa(server.sin_addr)];
        return ip;
    }
    /// 默认 IP
    return @"58.250.243.61";
}

你可能感兴趣的:(域名解析)