2

I want to find Mac and IP addresses of all the devices connected to the local network in Swift. I looked into AFNetworking/Alamofire, but it does not seem have the functionality I want. So, which API or Library I can use?

avi
  • 9,292
  • 11
  • 47
  • 84

2 Answers2

2

AFNetworking and Alamofire "only" handle requests. But as i understood you want to scan the local network for devices.

A quick Google search brought me to this: https://stackoverflow.com/a/21992359/2753395

Community
  • 1
  • 1
0

You can try to type "arp -a" in your Terminal, or use this in swift

        let theOutput = Pipe()

func shell(Path:String ,args: String...) -> Int32 {
    let task = Process()
    task.launchPath = Path
    task.arguments = args
    task.standardOutput = theOutput
    task.standardError = theOutput

    task.launch()
    task.waitUntilExit()

    return task.terminationStatus
}
shell(Path:"/usr/sbin/arp",args: "-a")

let theTaskData = theOutput.fileHandleForReading.readDataToEndOfFile()
let stringResult = String(data: theTaskData, encoding: .utf8)

print(stringResult!)
Allen Liu
  • 61
  • 1
  • 7
  • you have to "import Foundation" for this. Since there is an absolute path included, this will not make it through App Store validation probably. – Johan Velthuis Sep 22 '17 at 11:43