88
99#import " QNNExternalIp.h"
1010
11-
1211@implementation QNNExternalIp
1312
14- +(NSString *) externalIp {
13+ + (NSString *) externalIp {
1514 NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: @" http://whatismyip.akamai.com" ]];
1615 [urlRequest setHTTPMethod: @" GET" ];
17-
16+
1817 NSHTTPURLResponse *response = nil ;
1918 NSError *httpError = nil ;
2019 NSData *d = [NSURLConnection sendSynchronousRequest: urlRequest
@@ -23,23 +22,23 @@ +(NSString*) externalIp{
2322 if (httpError != nil || d == nil ) {
2423 return @" " ;
2524 }
26- NSString * s = [[NSString alloc ]initWithData:d encoding: NSUTF8StringEncoding];
25+ NSString * s = [[NSString alloc ] initWithData: d encoding: NSUTF8StringEncoding];
2726 if (s == nil ) {
2827 return @" " ;
2928 }
3029 return s;
3130}
3231
33- +(NSString *) externalDNS {
32+ + (NSString *) externalDNS {
3433 return @" " ;
3534}
3635
37- +(NSString *)getDiagUrl {
38- NSString * fetchurl = @" http://ns.pbt.cachecn.net/fast_tools/fetch_ldns_diag_client.php" ;
39-
36+ + (NSString *)getDiagUrl {
37+ NSString * fetchurl = @" http://ns.pbt.cachecn.net/fast_tools/fetch_ldns_diag_client.php" ;
38+
4039 NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: fetchurl]];
4140 [urlRequest setHTTPMethod: @" GET" ];
42-
41+
4342 NSHTTPURLResponse *response = nil ;
4443 NSError *httpError = nil ;
4544 NSData *d = [NSURLConnection sendSynchronousRequest: urlRequest
@@ -50,7 +49,7 @@ +(NSString*)getDiagUrl{
5049 return nil ;
5150 }
5251 NSLog (@" fetch http code %ld " , (long )response.statusCode );
53- NSString * s = [[NSString alloc ]initWithData:d encoding: NSUTF8StringEncoding];
52+ NSString * s = [[NSString alloc ] initWithData: d encoding: NSUTF8StringEncoding];
5453 if (s == nil || [s isEqualToString: @" " ]) {
5554 NSLog (@" fetch http code %ld " , (long )response.statusCode );
5655 return nil ;
@@ -61,10 +60,10 @@ +(NSString*)getDiagUrl{
6160 }
6261 s = [s substringFromIndex: range.location + range.length];
6362 range = [s rangeOfString: @" .php\" " ];
64- if (range.location > 4000 ) {
63+ if (range.location > 4000 ) {
6564 return nil ;
6665 }
67- s = [s substringToIndex: range.location+ 4 ];
66+ s = [s substringToIndex: range.location + 4 ];
6867 return s;
6968}
7069
@@ -85,15 +84,15 @@ +(NSString*)getDiagUrl{
8584// </pre>
8685// <p class="result">您的DNS配置正确! </p>
8786
88- +(NSString *)checkExternal {
89- NSString * url = [QNNExternalIp getDiagUrl ];
87+ + (NSString *)checkExternal {
88+ NSString * url = [QNNExternalIp getDiagUrl ];
9089 if (url == nil ) {
9190 return @" get fetch url failed" ;
9291 }
93-
92+
9493 NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: url]];
9594 [urlRequest setHTTPMethod: @" GET" ];
96-
95+
9796 NSHTTPURLResponse *response = nil ;
9897 NSError *httpError = nil ;
9998 NSData *d = [NSURLConnection sendSynchronousRequest: urlRequest
@@ -103,29 +102,29 @@ +(NSString*)checkExternal{
103102 return @" check server error" ;
104103 }
105104 NSLog (@" http code %ld " , (long )response.statusCode );
106- NSString * s = [[NSString alloc ]initWithData:d encoding: NSUTF8StringEncoding];
105+ NSString * s = [[NSString alloc ] initWithData: d encoding: NSUTF8StringEncoding];
107106 if (s == nil || [s isEqualToString: @" " ]) {
108107 return @" invalid encoding" ;
109108 }
110-
109+
111110 NSRange range = [s rangeOfString: @" <tr>" ];
112111 s = [s substringFromIndex: range.location + range.length];
113112 range = [s rangeOfString: @" </table>" ];
114113 s = [s substringToIndex: range.location];
115-
114+
116115 s = [s stringByReplacingOccurrencesOfString: @" </" withString: @" <" ];
117-
116+
118117 s = [s stringByReplacingOccurrencesOfString: @" <tr>" withString: @" " ];
119118 s = [s stringByReplacingOccurrencesOfString: @" <th>" withString: @" " ];
120119 s = [s stringByReplacingOccurrencesOfString: @" <td>" withString: @" " ];
121120 s = [s stringByReplacingOccurrencesOfString: @" <td>" withString: @" " ];
122121 s = [s stringByReplacingOccurrencesOfString: @" <td width=\" 128\" >" withString: @" " ];
123-
122+
124123 s = [s stringByReplacingOccurrencesOfString: @" <table>" withString: @" " ];
125124 s = [s stringByReplacingOccurrencesOfString: @" <p class=\" result\" >" withString: @" " ];
126125 s = [s stringByReplacingOccurrencesOfString: @" <pre>" withString: @" " ];
127126 s = [s stringByReplacingOccurrencesOfString: @" <p>" withString: @" " ];
128-
127+
129128 s = [s stringByReplacingOccurrencesOfString: @" \n\n " withString: @" \n " ];
130129 s = [s stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet ]];
131130 return s;
0 commit comments