Monday, August 26, 2013

Ping a particular host using objective c

Ping a host and check for reachability

So heres the code (Make sure you add the SystemConfiguration Framework in your project before you begin with this)

- (BOOL)pinghosttoCheckNetworkStatus
    bool success = false;
    const char *host_name = [@""
    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL,host_name);
    SCNetworkReachabilityFlags flags;
    success = SCNetworkReachabilityGetFlags(reachability, &flags);
    bool isAvailable = success && (flags & kSCNetworkFlagsReachable) &&
    !(flags & kSCNetworkFlagsConnectionRequired);
    if (isAvailable)
        return YES;
        return NO;

Happy iCoding and have a great day.

Join Us on Facebook


  1. Object oriented programing is a bit more difficult for everyone but it also gives best results on all platforms. Being a dedicated iPhone developers I have good fundamental concepts and can solve problems.

  2. I really wana thank you for providing such informative and qualitative material so often.
    IPhone 4S apps

  3. Wonderful share man... this code is not very complex in any means. And still i was unaware of this simple tactic of checking the availability of the host. you nailed it