Code Monkey home page Code Monkey logo

ipset's Introduction

Build Status

IpSet

A simple tool to enumerate IpAddress and check if an IP address is contained by the defined range or set.

Support both IPv4 and IPv6.

Support CIDR notation.

Install from NuGet

In the Package Manager Console:

PM> Install-Package IpSet

Use IpRange

IpRange represents a consecutive IP addresses.

Check an IP address.

    var range = IpRange.ParseOrDefault("192.168.0.0/16");
    var result = range.Contains("192.168.2.99"); // true

Support multiple parsing formats.

    [Theory]
    [InlineData("192.168.0.10 - 192.168.10.20", "192.168.20", true)]
    [InlineData("192.168.0.*", "192.168.0.255", true)]
    [InlineData("192.168.0.*", "192.168.1.0", false)]
    [InlineData("192.168.0.0/255.255.255.0", "192.168.1.100", false)]
    [InlineData("192.168.0.0/16", "192.168.2.99", true)]
    [InlineData("fe80::/10", "192.168.0.1", false)]
    [InlineData("192.168.0.10", "192.168.0.11", false)]
    public void Parse_And_Contains_Tests(string s, string testIp, bool expected)

Use IpSet

IpSet represents a group of IpRange instances. Ranges should be separated by comma when parsing.

IpSet is the recommended class over IpRange since it can hold one or multiple ranges. More features will be added on it later.

Check an IP address.

    var set = IpSet.ParseOrDefault("192.168.0.*,10.10.1.0/24,fe80::/10");
    var result = set.Contains("192.168.2.99"); // false
    result = set.Contains("10.10.1.200"); // true
    result = set.Contains("fe80::"); // true

Support multiple parsing formats.

Support any string conjunctions of IpRange formats by comma(","). Such as:

var set = IpSet.ParseOrDefault("192.168.0.10 - 192.168.10.20, 192.168.1.*, fe80::/10, 10.10.1.200");

ipset's People

Contributors

donnytian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

underscorehao

ipset's Issues

StyleCop is introducing warnings

Hi,

I've been using your package for some work I needed done last few days and I really like it. However there's an annoying behavior introduced by StyleCop. All of my projects are using tabs, not spaces, and every line with tabs is being flagged as a warning.

A .editorconfig file is a cleaner way to do the same I think :) I was thinking of doing a PR removing the StyleCop stuff or adding this line to GlobalSuppresions.cs

[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1027:Tabs must not be used", Justification = "Reviewed.")]

Would that be ok? Thanks!

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.