Skip to content

fdebrabander/swift-ipaddress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift IP address library

Library that contains types for IP addresses and networks.

import IPAddress

IPv4Network(string: "10.0.0.0/8").contains(ipaddress: IPv4Address(string: "10.1.0.1")

Including this library

Update your Package.swift file to include these lines.

let package = Package(
    dependencies: [
        .package(url: "https://github.com/fdebrabander/swift-ipaddress.git", from: "0.0.1"),
    ],
    targets: [
        .target(
            dependencies: ["IPAddress"]
        )
    ]
)

Quick guide

Create IPv4Address and IPv4Network objects

let ip1 = try IPv4Address(string: "192.168.0.1")
let ip2 = try IPv4Address(string: "10.0.0.1")
let network = try IPv4Network(string: "10.0.0.0/8")

Compare IP addresses

assert(ip1 != ip2, "should not match")

Determine if a network contains an IP address

assert(network.contains(ipaddress: ip2), "should contain ip")

Conversion between the different types

// Create an IPv4Network for network 192.168.0.0/16
let ip = try IPv4Address(string: "192.168.1.10")
ip.network(withPrefix: 16)

For the full documentation see the Swift Package Index.

About

IP address library for swift

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages