Resolve IP Address for hostname on the iPhone


March 17, 2010

iOS, UIKit

No Comment

On the Mac you might use NSHost, but as this is missing on the iPhone you are of using CFHost. Or much simpler use some standard C functions and you can easily get an IP Address for a hostname on the iPhone:


        // Get host entry info for given host
        struct hostent *remoteHostEnt = gethostbyname(“”);

        // Get address info from host entry
        struct in_addr *remoteInAddr = (struct in_addr *) remoteHostEnt->h_addr_list[0];

        // Convert numeric addr to ASCII string
        char *sRemoteInAddr = inet_ntoa(*remoteInAddr);

        NSString *s = [[NSString alloc] initWithFormat: @“Remote IP: %s\n”, sRemoteInAddr];

Do not forget that their might be more that one IP assigned to a hostname!

You can also get a nice tutorial at:

Related Posts

iPhone OS: Enterprise Business Tools

If you need to manage iPhones or iPads in a big enterprise business, your should read Apples Support Documents: and in any case download the iPhone Configuration Tools for Mac OS X: and for Windows: You can then setup configuration profiles, that reflect the setup of your environment: • Passcode-Richtlinien • Funktions-Einschränkungen […]

Read More

iPhone OS: Design a nice InApp Purchase View

To get up a nice InAppPurchase View for Apple’s AppStore, we first need some good looking buttons: There are also some tweaks for the UITableView you might consider using: more information upcoming…

Read More

Leave a Reply


  • An error has occurred, which probably means the feed is down. Try again later.