Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 1.75 KB

README.md

File metadata and controls

40 lines (30 loc) · 1.75 KB

NetworkScanner

GitHub code size in bytes GitHub build results

Provides a way to scan a specific network or the local networks for hosts which satisfy an arbitrary condition.

The API and implementation use Swift Structured Concurrency (await/async, Task, etc).

For example, to find all HTTPS servers on the local network that respond successfully to a request for their main page:

import Foundation
import NetworkScanner

let scanner = NetworkScanner(concurrencyLimit: 250) { address in
    guard let URL = URL(string: "https://\(address)") else {
        throw Errors.unableToConstructURL(address: address)
    }
    
    do {
        _ = try await session.data(from: URL)
        return .hit
    } catch {
        return .miss
    }
}

for try await result in scanner {
    print(result) // e.g. "192.168.0.10: Hit"
}

enum Errors: Error {
    case unableToConstructURL(address: String)
}

See the documentation for more details, as well as the included demo application for more probe examples.