1

I'm making a mac os app. I'm trying to get the ethernet and wlan addresses. I know these are en0 and en1 addresses but depending on devices, en0 can be the ethernet or the wlan one. Is there a way to know which one it is?

So far I'm using this which gets me both addresses but don't differentiate them:

let task=Process.init()
task.launchPath="/sbin/ifconfig"
task.arguments=["en0"]    //or en1

let pipe=Pipe()
task.standardOutput=pipe
task.launch()

let data=pipe.fileHandleForReading.readDataToEndOfFile()
guard let stringResult=String(data: data, encoding: String.Encoding.utf8) as NSString? else{wlanFailed();return}
print("en0:", stringResult)

EDIT

So now I'm trying to run this command networksetup -listnetworkserviceorder which works from my terminal.

But I don't know how to make it work from my Mac app. For example, with this:

let task=Process.init()
task.launchPath="/sbin/networksetup"
task.arguments=["-listnetworkserviceorder"]

I get:

launch path not accessible
Marie Dm
  • 2,637
  • 3
  • 24
  • 43

2 Answers2

1

These are some commands that help to match the interface with the hardware name:

  • networksetup -listallhardwareports

  • networksetup -listnetworkserviceorder

  • system_profiler SPNetworkDataType

  • scutil <<< "list" | grep -i airport

nbari
  • 25,603
  • 10
  • 76
  • 131
0

Thanks @artem-dorodovskiy and @nbari for giving me the command line.

I found how to write it thanks to this SOF answer.

let task=Process.init()
task.launchPath="/usr/bin/env"
task.arguments=["networksetup", "-listnetworkserviceorder"]
Marie Dm
  • 2,637
  • 3
  • 24
  • 43