0

i want to get Server IP address of wifi in iphone device . I do not want device ipaddress of wifi in iphone device... If there is any API for getting server IP address of wifi in iphone..Please refer that and share those links ...

Ex. My iPhone is connected to some XYZ wifi. Is it possible to get the Live IP address of the server that is providing the WIFI access?

Himanshu A Jadav
  • 2,286
  • 22
  • 34
megha
  • 905
  • 7
  • 17

1 Answers1

-1

Objective-C method to retrieve the IP address of the wifi connection as a NSString.

- (NSString *)getIPAddress 

{    NSString *address = @"error";    struct ifaddrs *interfaces = NULL;   struct ifaddrs *temp_addr = NULL;    int success = 0;

  // retrieve the current interfaces - returns 0 on success   

success= getifaddrs(&interfaces);    if (success == 0) 
         {
          // Loop through linked list of interfaces
     temp_addr = interfaces;
     while (temp_addr != NULL) 

{
       if( temp_addr->ifa_addr->sa_family == AF_INET) 

{
         // Check if interface is en0 which is the wifi connection on the iPhone
         if ([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) 

{
           // Get NSString from C String
           address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
         }
       }

       temp_addr = temp_addr->ifa_next;
     }   

}

   // Free memory   freeifaddrs(interfaces);

   return address; 

}

if this isn’t working for you you may need to include the following C headers in the top of your class implementation as well

#include <ifaddrs.h>
#include <arpa/inet.h>
Debabrata
  • 150
  • 2
  • 9
  • 1
    this give device IP address of wifi in iphone ,As per my requirement i need server IP address of wifi in iphone. – megha Nov 07 '12 at 07:58
  • did you checked these links (https://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html) https://developer.apple.com/library/mac/#samplecode/SimplePing/Introduction/Intro.html – Debabrata Nov 07 '12 at 08:08
  • i check these 2 links ,but does not got the sever IP address of wifi of iphone device. – megha Nov 07 '12 at 09:23