A library to help with getting IP addresses in Swift.
Add the following to your Package.swift
:
.package(url: "https://github.com/Samasaur1/SwiftIP.git", from: "2.0.0"),
Or use Ice:
$ ice add SwiftIP
The documentation is available here: https://samasaur1.github.io/SwiftIP/
Effectively, however, you do this:
import SwiftIP
guard let localIP = IP.local() else {
fatalError("Could not find local IP")
}
let publicIP: String? = IP.public()
print("Local IP: \(localIP); public IP: \(publicIP ?? "Not connected")")