Created
June 5, 2013 09:11
-
-
Save vclwei/5712660 to your computer and use it in GitHub Desktop.
Get External IP Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)getExternalIP{ | |
NSURLRequest *ipRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://checkip.dyndns.com"]]; | |
NSURLResponse *ipResponse = nil; | |
NSError *ipError = nil; | |
NSData *ipData = [NSURLConnection sendSynchronousRequest:ipRequest | |
returningResponse:&ipResponse | |
error:&ipError]; | |
NSString *ipInfo = [[[NSString alloc] initWithData:ipData encoding:NSUTF8StringEncoding] autorelease]; | |
NSLog(@"ipInfo %@", ipInfo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment