Splendidly detailed network and datalink-layer operations, tests, and utilities for Swift apps.
A Powerful, lightweight, and super fast framework that makes the often-difficult task of getting detailed network and datalink-layer information from the devices running your application.
Benefits:
- Fine-grained control over host reachability operations
- Gets detailed network interface information about the local device
- Enables retrieval of remote MAC addresses within local networks
- Enabled capture and storage of actual packets as
Codable
Swift objects (see docs forGBLPingResult
) - Fully documented in DocC
[Note: some of this documentation is about features that are not yet exposed]
Available via:
- Swift Package Manager: Github
Full documentation available via Github Pages
You can also run the test project from Projects/GBLPingExample/GBLPingExample.xcodeproj
and view the source for a functional example.
Also, see Unit Tests for information on tests, which also have implementation examples.
Implementation samples:
Reachability
Check if the device is online and able to reach the internet
import GBLPing
...
Ping.network.isReachable { reachable in
switch reachable {
case true:
proceedWithOperation()
case false:
handleOfflineOptions()
}
}
// Note: this will ping cloudflare’s
// nameserver `ns.cloudflare.com`
Reachability
Check if a given host is reachable by hostname
import GBLPing
...
Ping.host.isReachable(hostname: “google.com”) { reachable in
switch reachable {
case true:
handleForTrue()
case false:
handleForFalse()
}
}
Ping Hosts
Ping a given host by hostname continuously without stopping
import GBLPing
...
Ping.svc.pingHostname(
hostname: gigabitelabs.com,
maxPings: maxAttempts) { (reachable) in
// process only after all attempts
// have succeeded
switch reachable {
case true:
proceedWithOperation()
case false:
handleOfflineOptions()
}
}
Ping a given host by hostname, but limit the total pings to a given number
import GBLPing
...
GBLPing.svc.pingHostname(
hostname: gigabitelabs.com,
maxPings: maxAttempts) { (reachable) in
// process only after all attempts
// have succeeded
switch reachable {
case true:
proceedWithOperation()
case false:
handleOfflineOptions()
}
}
Network Interfaces
Get a list of the local device’s network interfaces
import GBLPing
...
// TODO: Docs
Network Interface Names
Get the names of all local network interfaces
import GBLPing
...
// TODO: Docs
Network Interface Info
Get information about a given network interface
import GBLPing
...
// TODO: Docs
- Clone the repository
cd
to root- Open Package.swift, or the .xcworkspace
- Select the appropriate target device
- Run tests
No UI tests are currently available, however, there IS a test project that will let you quickly run the implementation and view ping data.
Run the test project from Projects/GBLPingExample/GBLPingExample.xcodeproj
Typealiases
GBLPing
is typealiased toPing
for convenience and simplicity
This framework is a mixed Swift & Obj-C package that contains work by Apple and a few others.