Developing iOS does make people happy (as opposed to deskop,android), and iOS apps are more focused on their own experience and performance. This is very good, I like the relatively perfect thing very much.
Recently met with some messy needs. Need to get some device information, network situation. Development on IOS is very simple and fun, except for some messy information, such as: Camera hardware information, local photo album initialization time (first time photo save), etc.
The rest of the information is what I want:
or the Code demo:
#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/"
//get the local DNS IP+ (Nsdictionary *) Getdnsip {res_state res= (res_state) malloc (sizeof(struct__res_state)); __uint32_t Dwdnsip=0; intresult =Res_ninit (RES); if(Result = =0) {Dwdnsip= res->nsaddr_list[0].sin_addr.s_addr; } free (res); NSString*dns = [NSString Stringwithutf8string:inet_ntoa (res->nsaddr_list[0].sin_addr)]; Nsdictionary*tmp = [[Nsdictionary alloc] Initwithobjectsandkeys:dns,@"Localdns", nil]; returntmp;}
//Get IP address for domain name development+ (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 what it failed if(Result = =TRUE) {Addresses= Cfhostgetaddressing (Hostref, &result); } } if(Result = =TRUE) {Nsmutablearray*tempdns =[[Nsmutablearray alloc] init]; for(inti =0; I < Cfarraygetcount (addresses); i++){ structsockaddr_in*remoteaddr; Cfdataref Sadata=(CFDATAREF) Cfarraygetvalueatindex (addresses, i); Remoteaddr= (structsockaddr_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];}
/ * Third party access to extranet ip*/
//Full Real 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:0Range:nsmakerange (0, [responsestr length])]; for(Nstextcheckingresult *matchinchmatches) {[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:0Range:nsmakerange (0, [responsestr length])]; for(Nstextcheckingresult *matchinchmatches) {[Pos_array addobject:[responsestr substringWithRange:match.range]];//NSLog (@ "Device location:%@", [Responsestr SubstringWithRange:match.range]);}} [dic Setvalue:ip_array Forkey:@"IP"]; [DiC setvalue:pos_array Forkey:@"Positon"]; } Else{[dic setvalue:error Forkey:@"Get Error"]; } returnDiC;}//NetEase 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:0Range:nsmakerange (0, [responsestr length])]; if([matches count]! =1) {[dic setValue:@"count! = 1"Forkey:@"Get Error"]; returndic; } for(Nstextcheckingresult *matchinchmatches) {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:@"Your IP address information:. *? (?=<br>)"Options:nsregularexpressioncaseinsensitive error:&ERROR]; if(Error = =Nil) {Nsarray*matches =[Regex matchesinstring:resstr options:0Range:nsmakerange (0, [resstr length])]; for(Nstextcheckingresult *matchinchmatches) {[Ip_array addobject:[resstr substringWithRange:match.range]];//NSLog (@ "IP msg:%@", [Resstr SubstringWithRange:match.range]);}} Regex= [Nsregularexpression Regularexpressionwithpattern:@"your DNS address information:. *? (?=<br>)"Options:nsregularexpressioncaseinsensitive error:&ERROR]; if(Error = =Nil) {Nsarray*matches =[Regex matchesinstring:resstr options:0Range:nsmakerange (0, [resstr length])]; for(Nstextcheckingresult *matchinchmatches) {[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"]; } returnDiC;}
#pragma mark-devicemsg//IDFA IDFV Basic device Information -(void) getdevmsg { * Device=[[Uidevice alloc] init]; *idfastring = [[[Asidentifiermanager Sharedmanager] advertisingidentifier] uuidstring];}
#pragmaMark-wifistatus//Get Wi-Fi information (if WiFi is linked)- (void) detectwifi{Nsarray*ifs = (__bridge_transferID) cncopysupportedinterfaces (); IDinfo =Nil; for(NSString *ifnaminchIFS) {Info= (__bridge_transferID) Cncopycurrentnetworkinfo ((__bridge cfstringref) Ifnam); if(Info! =Nil) { //Todu}} [self Finishstatus:@"WiFi"];}
iOS device basic information detection