Skip to content

Instantly share code, notes, and snippets.

@vclwei
Created June 5, 2013 09:11
Show Gist options
  • Save vclwei/5712660 to your computer and use it in GitHub Desktop.
Save vclwei/5712660 to your computer and use it in GitHub Desktop.
Get External IP Address
+ (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