The swift-ip library is a portable, Foundation-free library for working with IP addresses. It provides tools for parsing and formatting IP addresses, data structures for performing efficient IP address lookups, and shims for compatibility with types from other libraries such as SwiftNIO.
One of the goals of this library is to allow other libraries to exchange strongly-typed values with zero overhead without falling back to raw integer representations or linking against large frameworks.
The swift-ip library requires Swift 6.0 or later. This is because IP.V6
uses UInt128
.
Platform | Status |
---|---|
🐧 Linux | |
🍏 Darwin | |
🍏 Darwin (iOS) | |
🍏 Darwin (tvOS) | |
🍏 Darwin (visionOS) | |
🍏 Darwin (watchOS) |
The IP address types defined by the Network
framework are Darwin-only, which precludes their use in server-side code.
The swift-nio library provides a multi-platform SocketAddress
type, but it is heap-allocated and reference-counted, and requires linking against the entire NIOCore
module. This makes it unsuitable as a high-performance currency type for purposes such as firewall implementations or metrics collection.
The Swiftinit documentation index currently uses the swift-ip library to verify clients (such as Googlebot and GitHub Webhooks) and combat abuse.
The swift-ip library is Apache 2.0 licensed.