2012-11-07 4 views
0

iphone 디바이스에서 wifi의 서버 IP 주소를 얻고 싶습니다. 내가 아이폰 장치에 와이파이의 장치 ipaddress 싶지 않아요 ... 아이폰에 와이파이의 서버 IP 주소를 얻기위한 API가 있다면 ... 제발 그 참조하고 그 링크를 공유 참조하십시오 ...iphone 디바이스의 wifi 서버 IP 주소

예. 내 iPhone이 일부 XYZ 무선 랜에 연결되어 있습니다. WIFI 액세스를 제공하는 서버의 실 IP 주소를 가져올 수 있습니까?

+0

를 다음과 같은 C 헤더를 포함해야 '? – Osiris

+0

우리가 연결된 와이파이의 서버, 그 서버의 IP 주소가 필요합니다. – megha

+0

undastand 수 없습니다 당신의 노력에 대해 더 명확히 해 주시기 바랍니다 –

답변

-1

Wifi 연결의 IP 주소를 NSString으로 검색하는 Objective-C 메소드입니다.

- (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; 

} 

이 당신을 위해 작동하지 않는 경우 당신은 당신이 무선 랜의 서버 IP 주소 '가 무슨 뜻 이죠뿐만 아니라 당신의 클래스 구현의 상단에

#include <ifaddrs.h> 
#include <arpa/inet.h> 
+1

이것은 아이폰에 와이파이의 장치 IP 주소를 제공, 내 요구에 따라 아이폰에 와이파이의 서버 IP 주소가 필요합니다. – megha

+0

이 링크 (https://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html)를 확인 했습니까? https://developer.apple.com/library/mac/#samplecode/SimplePing /Introduction/Intro.html – Debabrata

+0

이 두 링크를 확인했지만 아이폰 기기의 wifi의 IP 주소가 정확하지 않습니다. – megha