How can I get the list of all active network interfaces programmatically?
28
votes
3
answers
104577
views
My objective is to determine the IP address for Ethernet on a device. But assuming that there are connections like WiFi and USB Ethernet, is there a particular way just to get the Ethernet IP ?
On a shell I would do
networksetup -listallhardwareports
which would give me a mapping of Hardware Port to Device. From that I would grep the device for Hardware Port: Ethernet and then use ifaddr struct to get my IP.
I know the ifaddr part, please suggest how to do the first part programmatically.
Also, is there an alternative approach ?
Asked by user447851
(389 rep)
Feb 10, 2016, 05:09 AM
Last activity: Oct 8, 2024, 02:59 PM
Last activity: Oct 8, 2024, 02:59 PM