IOS 获取手机ip地址
2014-06-20 16:30
351 查看
#include <ifaddrs.h> #include <arpa/inet.h> - (NSString *)getIPAddress { NSString *address = @"error"; struct ifaddrs *interfaces = NULL; struct ifaddrs *temp_addr = NULL; int success = 0; // retrieve the current interfaces - returns 0 on success success = getifaddrs(&interfaces); if (success == 0) { // Loop through linked list of interfaces temp_addr = interfaces; while (temp_addr != NULL) { if( temp_addr->ifa_addr->sa_family == AF_INET) { // Check if interface is en0 which is the wifi connection on the iPhone if ([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) { // Get NSString from C String address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]; } } temp_addr = temp_addr->ifa_next; } } // Free memory freeifaddrs(interfaces); return address; }
相关文章推荐
- iOS怎样获取手机的ip地址
- iOS 获取手机设备IP地址的两种方法
- iOS获取手机ip地址代码
- iOS 获取手机当前所连接的网络的IP地址
- iOS 获取手机设备IP地址的两种方法
- iOS开发之 获取手机的网络的ip地址
- IOS开发 手机联系人获取与使用ABAddressBookRef
- 一个有用的类,集合了建立、连接热点;获取本机ip和连接此热点的手机的ip地址等方法
- iOS 获取手机的型号,系统版本,软件名称,软件版本
- iOS 获取手机的型号,系统版本,软件名称,软件版本
- iOS 获取手机的型号,系统版本,软件名称,软件版本
- iOS学习笔记(十三)——获取手机信息(UIDevice、NSBundle、NSLocale)
- 手机连不上wifi,一直显示正在获取ip地址
- iOS 获取手机的型号,系统版本,软件名称,软件版本
- iOS 获取本地IP地址
- Android 手机上获取手机当前上网IP地址(手机网关给手机号分配的IP)