Convert Network Interface Name

后端 未结 1 720
说谎
说谎 2020-12-22 02:28

I am trying to get a list of active network interfaces with end user understandable names. Like the names listed in System Preferences instead of en0 en5<

相关标签:
1条回答
  • 2020-12-22 02:52

    This is possible with System Configuration on macOS. In Objective-C like so:

        CFArrayRef ref = SCNetworkInterfaceCopyAll();
        NSArray* networkInterfaces = (__bridge NSArray *)(ref);
        for(int i = 0; i < networkInterfaces.count; i += 1) {
            SCNetworkInterfaceRef interface = (__bridge SCNetworkInterfaceRef)(networkInterfaces[i]);
    
            CFStringRef displayName = SCNetworkInterfaceGetLocalizedDisplayName(interface);
            CFStringRef bsdName = SCNetworkInterfaceGetBSDName(interface);
            NSLog(@"Name:%@  \ninterface: %@\nbsd:%@",displayName, SCNetworkInterfaceGetInterfaceType(interface), bsdName);
    
        }
    

    The localized display name will be something like Display Ethernet or WiFi and the BSD name will be something like en5 which will allow matching to the above code.

    This approach doesn't work on iOS, but there aren't really any other configurations on iOS anyway.

    0 讨论(0)
提交回复
热议问题