Reputation: 31
Given a URL like: https://dl.google.com/chrome/mac/stable/GGRM/googlechrome.dmg
,
how can I get the IP address, e.g., 74.125.224.140
, in the Cocoa framework or with an Objective-C method?
Upvotes: 0
Views: 2703
Reputation: 11544
This worked for me
#import <netdb.h>
#include <arpa/inet.h>
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
struct hostent *host_entry = gethostbyname(charUrl);
char *buff = inet_ntoa(*((struct in_addr *)host_entry->h_addr_list[0]));
});
Thanks to: source
Upvotes: 0
Reputation: 379
try this. I think that is what you expecting.
From domain name you can get address as given below.
NSURL *validURL = [NSURL URLWithString: yourUrl];
NSString *host = [validURL host];
NSString *ipAdress = [[NSHost hostWithName:host]address];
Upvotes: 4
Reputation: 3294
Try this:
NSString *ip = [[NSHost hostWithName:(NSString *)yourDomainNameUrl] address];
Upvotes: 2