2012-06-23 13 views
7

私はデバイスのMacとIPアドレスを取得します。しかし、デバイス名を取得しないでください。iPhone SDKでデバイス名をプログラムで取得する方法は?

デバイスの「ネットワークユーティリティ」のように、可能な場合はどうすればより多くの情報を得ることができますか?

のiOS 4.1以降で
+0

こんにちはDhaval、あなたがこのためにどんな解決策を見つけますか? – iBhavik

+0

@ i-bhavikを共有してください。デバイス名を取得できませんでした。デバイス情報を取得します。 – Dhaval

+0

誰もがこれを進歩していますか?私はまた、iNetのように、私のアプリにデバイス名を見つけてもらいたい。私はpingできます、私はARPテーブルを読むことができます、私はマシン名を見つけることができません。どんな助けもありがとう! – Jelle

答えて

3

、あなたがこれを行うことができます:あなたはSSID名を探しているなら...

輸入

- (id)fetchSSIDInfo 
{ 
    NSArray *ifs = (id)CNCopySupportedInterfaces(); 
    NSLog(@"%s: Supported interfaces: %@", __func__, ifs); 
    id info = nil; 
    for (NSString *ifnam in ifs) { 
     info = (id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam); 
     NSLog(@"%s: %@ => %@", __func__, ifnam, info); 
     if (info && [info count]) { 
      break; 
     } 
     [info release]; 
    } 
    [ifs release]; 
    return [info autorelease]; 
} 
+0

ありがとう、しかし、私は私のデバイスでpingの別の接続されたデバイスを取得したい他のデバイス情報はネットワークinfo.like私は私のデバイス名 "iPhone simulater"他のルータデバイス情報に接続されたこのタイプの名前を取得します。もしあなたが何か考えがあれば教えてください。 – Dhaval

+0

@Dhaval:iPhone Simulator以外のデバイスでこのコードを使用してみてください。これをあなたのデバイスで使用すると、ルータのSSID、Macアドレスなどが取得されます。 – Deepak

12
NSLog(@"uniqueIdentifier: %@", [[UIDevice currentDevice] uniqueIdentifier]); 
NSLog(@"name: %@", [[UIDevice currentDevice] name]); 
NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]); 
NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]); 
NSLog(@"model: %@", [[UIDevice currentDevice] model]); 
NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]); 
+0

それは現在のデバイス情報を提供していますが、ネットワーク上の別の接続デバイスを取得する必要があります。その名前/ mac/ipアドレスのthat.iはmacとipを取得しますが、デバイス名は取得しません。 – Dhaval

+0

manish @デバイスの情報を取得する任意のアイデア? – Dhaval

+0

Nops !! .......... – Mani

1
#import <ifaddrs.h> 
#import <arpa/inet.h> 

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

} 
+0

私はすでにipとmacのデバイス名を取得しないでください。それを取得するには? – Dhaval

関連する問題