ios 设备基本信息检测
开发ios确实会让人身心愉悦(相对于deskop,android),ios app更多的让人集中注意力到它本身的体验,性能。这非常好,我非常喜欢相对完美的事物。
最近遇到一些乱七八糟的需求。需要获取一些设备信息,网络情况。iOS 上开发非常简单有趣,除了一些乱七八糟的信息,例如:摄像头硬件信息,本地相册初始化时间(第一次拍照保存),等。
剩下一些信息就是我要的了:
还是代码演示:
#define IOS_CELLULAR @"pdp_ip0"
#define IOS_WIFI @"en0"
#define IP_ADDR_IPv4 @"ipv4"
#define IP_ADDR_IPv6 @"ipv6"
#define ADDRESSIP @"http://www.cz88.net/ip/viewip778.aspx"
#define ADDRESSIPWY @"http://nstool.netease.com/"
//获取本地的DNS IP
+ (NSDictionary *)getDNSIp {
res_state res = (res_state)malloc(sizeof(struct __res_state));
__uint32_t dwDNSIP = ;
int result = res_ninit(res);
if (result == ) {
dwDNSIP = res->nsaddr_list[].sin_addr.s_addr;
}
free(res);
NSString *dns = [NSString stringWithUTF8String:inet_ntoa(res->nsaddr_list[].sin_addr)];
NSDictionary *tmp = [[NSDictionary alloc] initWithObjectsAndKeys: dns, @"LocalDNS", nil];
return tmp;
}
//获取制定域名的IP地址
+ (NSDictionary *)ServersToIp:(NSString *)ip {
Boolean result;
CFHostRef hostRef;
CFArrayRef addresses=nil;
NSString *hostname = ip;
NSMutableArray *array = [[NSMutableArray alloc] init];
hostRef = CFHostCreateWithName(kCFAllocatorDefault, (__bridge CFStringRef)hostname);
if (hostRef) {
result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL); // pass an error instead of NULL here to find out why it failed
if (result == TRUE) {
addresses = CFHostGetAddressing(hostRef, &result);
}
}
if (result == TRUE) {
NSMutableArray *tempDNS = [[NSMutableArray alloc] init];
for(int i = ; i < CFArrayGetCount(addresses); i++){
struct sockaddr_in* remoteAddr;
CFDataRef saData = (CFDataRef)CFArrayGetValueAtIndex(addresses, i);
remoteAddr = (struct sockaddr_in*)CFDataGetBytePtr(saData); if(remoteAddr != NULL){
// Extract the ip address
//const char *strIP41 = inet_ntoa(remoteAddr->sin_addr);
NSString *strDNS =[NSString stringWithCString:inet_ntoa(remoteAddr->sin_addr) encoding:NSASCIIStringEncoding];
[array addObject:strDNS];
[tempDNS addObject:strDNS];
}
}
} else {
NSLog(@"Not resolved");
}
return [NSDictionary dictionaryWithObjectsAndKeys: array, ip, nil];
}
/*第三方获取外网ip*/
//全真ip
+ (NSDictionary*)getWanIPAddress {
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
NSMutableArray *ip_array = [[NSMutableArray alloc] init];
NSMutableArray *pos_array = [[NSMutableArray alloc] init];
NSURLRequest *request = [NSMutableURLRequest requestWithURL:[[NSURL alloc]initWithString: ADDRESSIP] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0];
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
if (error == nil) {
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString *responseStr = [[NSString alloc] initWithData:data encoding:enc];
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" options:NSRegularExpressionCaseInsensitive error:&error];
if (error == nil) {
NSArray *matches = [regex matchesInString:responseStr
options:
range:NSMakeRange(, [responseStr length])];
for (NSTextCheckingResult *match in matches) {
[ip_array addObject:[responseStr substringWithRange:match.range]];
// NSLog(@"the ip address:%@", [responseStr substringWithRange:match.range]);
}
}
regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=AddrMessage\">).*(?=</spa)" options:NSRegularExpressionCaseInsensitive error:&error];
if (error == nil) {
NSArray *matches = [regex matchesInString:responseStr
options:
range:NSMakeRange(, [responseStr length])];
for (NSTextCheckingResult *match in matches) {
[pos_array addObject:[responseStr substringWithRange:match.range]];
// NSLog(@"设备位置:%@", [responseStr substringWithRange:match.range]);
}
}
[dic setValue:ip_array forKey:@"ip"];
[dic setValue:pos_array forKey:@"positon"];
} else {
[dic setValue:error forKey:@"get error"];
}
return dic;
} //网易ip
+ (NSDictionary*)getWanIPAddressWY {
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
NSMutableArray *ip_array = [[NSMutableArray alloc] init];
NSMutableArray *dns_array = [[NSMutableArray alloc] init];
NSURLRequest *request = [NSMutableURLRequest requestWithURL:[[NSURL alloc]initWithString: ADDRESSIPWY] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0];
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
if (error == nil) {
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString *responseStr = [[NSString alloc] initWithData:data encoding:enc];
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=<iframe src=').*(?=' frameborder)" options:NSRegularExpressionCaseInsensitive error:&error];
if (error == nil) {
NSArray *matches = [regex matchesInString:responseStr
options:
range:NSMakeRange(, [responseStr length])];
if ([matches count] != ) {
[dic setValue:@"count != 1" forKey:@"get error"];
return dic;
}
for (NSTextCheckingResult *match in matches) {
request = [NSMutableURLRequest requestWithURL:[[NSURL alloc]initWithString: [responseStr substringWithRange:match.range]] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0];
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
if (error == nil) {
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString *resStr = [[NSString alloc] initWithData:data encoding:enc];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"您的IP地址信息:.*?(?=<br>)" options:NSRegularExpressionCaseInsensitive error:&error];
if (error == nil) {
NSArray *matches = [regex matchesInString:resStr
options:
range:NSMakeRange(, [resStr length])];
for (NSTextCheckingResult *match in matches) {
[ip_array addObject:[resStr substringWithRange:match.range]];
// NSLog(@"ip msg:%@", [resStr substringWithRange:match.range]);
}
}
regex = [NSRegularExpression regularExpressionWithPattern:@"您的DNS地址信息:.*?(?=<br>)" options:NSRegularExpressionCaseInsensitive error:&error];
if (error == nil) {
NSArray *matches = [regex matchesInString:resStr
options:
range:NSMakeRange(, [resStr length])];
for (NSTextCheckingResult *match in matches) {
[dns_array addObject:[resStr substringWithRange:match.range]];
// NSLog(@"DNS msg:%@", [resStr substringWithRange:match.range]);
}
}
[dic setValue:ip_array forKey:@"ip"];
[dic setValue:dns_array forKey:@"positon"];
}
}
} else {
[dic setValue:@"count != 1" forKey:@"get error"];
}
} else {
[dic setValue:@"count != 1" forKey:@"get error"];
}
return dic;
}
#pragma mark - deviceMsg
//idfa idfv 基本的设备信息
- (void)getDevMsg {
UIDevice *device=[[UIDevice alloc] init];
NSString *idfaString = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
}
#pragma mark - wifiStatus
//获取Wi-Fi信息(如果链接了wifi)
- (void)detectWifi{
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
id info = nil;
for (NSString *ifnam in ifs) {
info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
if(info != nil){
//TODU
}
}
[self finishStatus:@"wifi"];
}
ios 设备基本信息检测的更多相关文章
- 获取IOS 设备基本信息
原地址:http://www.cnblogs.com/U-tansuo/p/ios_basis_info.html 1.获取设备类型 (Iphone/ipad 几?) #import "s ...
- [原]IOS 设备基本信息
1.获取设备类型 (Iphone/ipad 几?) #import "sys/utsname.h" -(NSString*)getDeviceVersion{ struct ...
- IOS设备 UIDevice 获取操作系统 版本 电量 临近手机触发消息检测 (真机亲测可用)
- (void)viewDidLoad { [super viewDidLoad]; // 操作系统 NSString * osName =[[UIDevice currentDevice]syste ...
- [转]iOS设备唯一标识探讨
转自:http://www.jianshu.com/p/b83b0240bd0e iOS设备唯一标识探讨 为了统计和检测应用的使用数据,几乎每家公司都有获取唯一标识的业务需求,在iOS5以前获取唯一标 ...
- iOS学习——获取iOS设备的各种信息
不管是在Android开发还是iOS开发过程中,有时候我们需要经常根据设备的一些状态或信息进行不同的设置和性能配置,例如横竖屏切换时,电池电量低时,内存不够时,网络切换时等等,我们在这时候需要进行一些 ...
- Mac平台下部署UE4工程到iOS设备的流程
1.开发环境 UE4.Xcode.iOS版本情况如下: 1.UE4:当前最新版本Unreal Engine 4.17.2. 2.Xcode:当前最新版本Xcode9.0. 3.iOS:当前最新版本iO ...
- 经验之道:最有效的iOS内存泄漏检测
版权声明:本文由胡涛原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/125 来源:腾云阁 https://www.qclou ...
- 使用Safari远程调试iOS设备网页
最近在做HTML 5游戏时,发布到手机上访问网页总是莫名其妙出现问题,苦于没有remote debug功能一直没有查找到问题. 这边博客详细介绍了iOS, Android, Windows Phone ...
- 使用Fiddler对Android或者iOS设备进行抓包
1.PC端Fiddler配置 Tools->HTTPS->选中“Decrpt HTTPS traffic”,“Ignore server certificate errors” Tools ...
随机推荐
- 4安德鲁斯.2.2在系统,具有系统权限的应用程序无法读取或写入SD卡
有两个解决方案: 1.通过改动android系统的源代码,开放SD卡的读写权限,具体的改动方法和说明.能够參考网上资料http://www.ifeegoo.com/android-debug-stat ...
- NuttX 介绍
(嵌入式 实时操作系统 rtos nuttx 7.1) NuttX 介绍 转载请注明出处:http://blog.csdn.net/zhumaill/article/details/24197637 ...
- CSDN Androidclient生产 导航帖
弄个导航棒.的相关知识汇总. CSDN Android的client的效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG1qNjIzNTY1Nzk ...
- js便签笔记(13)——jsonp事实上非常easy【ajax跨域请求】
前两天被问到ajax跨域怎样解决,还真被问住了,光知道有个什么jsonp,迷迷糊糊的没有说上来.抱着有问题必须解决的态度,我看了很多资料,原来如此.. . 为何一直知道jsonp,但一直迷迷糊糊的不明 ...
- 将node-expat扩展编译至node.exe中
1.下载node源代码 https://github.com/joyent/node (v:0.10.25) 2.下载node-expat源代码 https://github.com/node-xmp ...
- html 块状元素 行内元素 内联元素
块状(Block)类型的元素的width默认为100%,而行内(Inline)类型的元素则是根据自身的内容及子元素来决定宽度. 块元素(block element) address - 地址 bloc ...
- ASP.NET MVC (Razor)开发
ASP.NET MVC (Razor)开发 过去我们使用过一些周报工具来完成项目组或部门的周报填写与考核工作,但多少有些不理想,要么功能太过简单,要么功能特别繁杂,不接地气,使用不便. 后来我们就考虑 ...
- sql语句like的使用方法
在SQL结构化查询语言中,LIKE语句有着至关关键的数据. LIKE语句的语法格式是:select * from 表名 where 字段名 like 相应值(子串),它主要是针对字符型字段的,它的作用 ...
- Eclipse—怎样为Eclipse开发工具中创建的JavaWebproject创建Servlet
在博客<在Eclipse中怎样创建JavaWebproject>中图文并茂的说明了Eclipse中创建JavaWebproject的方法,本篇博客将告诉大家怎样为Eclipse开发工具中创 ...
- Cocos2d-X中的坐标系
在Cocos2d-x中坐标能够分成四种: 1.GL坐标体系:GL坐标体系左下角为坐标原点,X轴向右,Y轴向上 2.UI坐标体系:UI坐标体系左上角为坐标原点,X轴向右,Y轴向上. .世界坐标体系:是窗 ...