根据域名动态获取IP地址(iOS)
2017-07-07 14:16
609 查看
需要导入以下头文件
具体方法为
#include <netdb.h> #include <sys/socket.h> #include <arpa/inet.h>
具体方法为
- (NSString*)getIPWithHostName:(const NSString*)hostName { const char *hostN= [hostName UTF8String]; struct hostent* phot; @try { phot = gethostbyname(hostN); if (phot == nil) { return nil; } } @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; }
相关文章推荐
- ios中 根据域名动态获取ip地址
- iOS 根据域名获取ip地址
- vc根据域名获取IP地址 gethostbyname()函数
- C# 根据域名获取IP地址
- vc根据域名获取IP地址 gethostbyname()函数
- 一、java根据域名获取ip地址
- vc根据域名获取IP地址 gethostbyname()函数
- [Win32]根据主机名、域名、IP字符串获取IP地址
- Java学习笔记之网络编程基础-根据域名自动到DNS上获取IP地址
- 根据域名获取ip地址
- vc根据域名获取IP地址 gethostbyname()函数
- VC++根据域名获取IP地址GetHostByName()
- iOS版本号,build号获取,根据字符串格式长短动态计算uilabel的size等
- 根据域名获取IP地址,并探测是否可达
- C/C++ 根据域名获取IP地址
- 根据域名获取IP地址
- 根据域名获取IP地址
- java网络编程根据域名获取ip地址,URL
- vc根据域名获取IP地址 gethostbyname()函数
- 根据域名获取IP地址 gethostbyname()函数