iOS 域名解析
来源:互联网 发布:mysql的全文索引 编辑:程序博客网 时间:2024/04/29 18:48
如何在iOS下进行域名的解析?
/**
* 域名解析ip
*
* @param hostName 域名
*
* @return ip
*/
+(NSString *) getIPWithHostName:(const NSString *)hostName
{
const char *hostN= [hostName UTF8String];
struct hostent* phot;
@try {
phot = gethostbyname(hostN);
}
@catch (NSException *exception) {
return nil;
}
struct in_addr ip_addr;
memcpy(&ip_addr, phot->h_addr_list[0], 4);
char ip[20] = {0};
inet_ntop(AF_INET, &ip_addr, ip, sizeof(ip));
NSString* strIPAddress = [NSString stringWithUTF8String:ip];
return strIPAddress;
}
NSString *ip = [DomainNameResolution getIPWithHostName:@"www.baidu.com"];
NSLog(@"%@",ip);
打印结果:
2016-08-21 10:31:57.653 DomainNameResolution[1284:37374] 14.215.177.38
Demo地址:https://github.com/JnKindle/DomainNameResolution
- iOS域名解析
- iOS 域名解析
- iOS DNS域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 域名解析
- 满满的都是爱
- VMware中三种网络连接的区别
- Dark感觉不错的一篇文章。Redis主从复制和集群配置
- Linux common commands
- GCD-异步全局队列
- iOS 域名解析
- 配置Project分环境打包时遇到的问题
- Oracle 数据字典详解
- XMPP学习3-IM即时消息
- remote: Permission to CocoaPods/Specs.git
- 气泡法排序
- 零碎知识总结
- role属性解析
- Mpc8306开发环境的搭建