OC实现域名转IP
来源:互联网 发布:手机淘宝排名规则 编辑:程序博客网 时间:2024/06/04 18:01
#include <stdio.h>#include <netdb.h>#include <sys/socket.h>#include <arpa/inet.h>#include <string.h>#include <ifaddrs.h>+(NSArray *)getIPWithHostName:(NSString *)current_hostname{ struct hostent *hs; struct sockaddr_in server; const char *hostname = current_hostname.UTF8String; NSMutableArray *OC_IP_ARRAY = [NSMutableArray array]; if ((hs = gethostbyname(hostname)) != NULL){ server.sin_addr = *((struct in_addr*)hs -> h_addr_list[0]); inet_ntoa(*(struct in_addr *)hs->h_addr_list[0]); int i = 0; while (hs->h_addr_list[i]) { printf("%s+++\n", inet_ntoa(*(struct in_addr *)hs->h_addr_list[i])); char* IP = inet_ntoa(*(struct in_addr *)hs->h_addr_list[i]); NSString *OC_IP = [NSString stringWithCString:IP encoding:NSUTF8StringEncoding]; [OC_IP_ARRAY addObject:OC_IP]; i++; } return OC_IP_ARRAY; } return nil;}
使用的时候直接传给他一个域名就可以,返回的值有可能是nil使用的时候需要判断一下,在swift里建立桥接文件也能正常使用
0 0
- OC实现域名转IP
- 域名转ip地址编程实现
- c#域名转ip
- linux 域名转ip
- 域名转IP
- 域名转IP例程
- Linux下c实现域名转IP的方法封装
- IOS IPV6域名转IP
- C++ 域名转IP地址
- C#实现根据域名查询ip实例
- Linux下c实现 IP转为域名
- JAVA实现通过IP反查域名
- C#实现根据域名查询ip实例
- Python 实现IP动态绑定pubyun 域名
- 使用python实现IP反查域名
- 域名转换IP的一种实现方法
- 域名转化到IP地址的实现
- windows网络编程 实现域名查询ip
- Python print函数用法,print 格式化输出
- 最少拦截系统
- TCPServer框架(翻译官网pdf)
- windows 10下 scala运行环境搭建
- linux驱动头文件位置的说明
- OC实现域名转IP
- How to install plugin for Eclipse from .zip
- MySQL慢查询日志总结
- 报表评估
- 51NOD 1096 距离之和最小
- asp.net弹出提示框后页面重定向方法!
- Guess Number Higher or Lower
- ADB 用法大全
- 配置服务器出错 /usr/libexec/gconf-sanity-check-2的退出状态为256