Coder Social home page Coder Social logo

swift-ipaddress's Introduction

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.

swift-ipaddress's People

Contributors

fdebrabander avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.