Coder Social home page Coder Social logo

Example 9 is broken about ipnetwork HOT 1 CLOSED

lduchosal avatar lduchosal commented on August 29, 2024
Example 9 is broken

from ipnetwork.

Comments (1)

lduchosal avatar lduchosal commented on August 29, 2024

Dear BigPacket,

Thanks for your question. There are 2 methodes that behave almost identically :

IPNetwork.TrySupernet
IPNetwork.TryWideSubnet

TrySupernet will merge only consecutive subnets (192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23)
TryWideSubnet will find the smallest subnet that can contains the subnet in argument (192.168.0.0/24 + 192.168.10.0/24 = 192.168.0.0/20)

https://github.com/lduchosal/ipnetwork/blob/master/src/System.Net.IPNetwork.TestProject.Source/IPNetworkUnitTest.cs

`

    [TestMethod]
    public void When_TrySupernet_192_168_0_0_cidr24_add_192_168_10_0_cidr24_Then_Should_Invalid()
    {

        IPNetwork network = IPNetwork.Parse("192.168.0.0/24");
        IPNetwork network2 = IPNetwork.Parse("192.168.10.0/24");

        bool supernetted = network.TrySupernet(network2, out var ipnetwork);
        Assert.AreEqual(false, supernetted);


    }

    [TestMethod]
    public void When_TryWideSubnet_192_168_0_0_cidr24_add_192_168_10_0_cidr24_Then_Should_Invalid()
    {

        IPNetwork network = IPNetwork.Parse("192.168.0.0/24");
        IPNetwork network2 = IPNetwork.Parse("192.168.10.0/24");

        bool wideSubnetted = IPNetwork.TryWideSubnet(new[] { network, network2 }, out IPNetwork ipnetwork);
        Assert.AreEqual(true, wideSubnetted);
        Assert.AreEqual("192.168.0.0/20", ipnetwork.ToString());

        Console.WriteLine("Network : {0}", ipnetwork.Network);
        Console.WriteLine("Netmask : {0}", ipnetwork.Netmask);
        Console.WriteLine("Broadcast : {0}", ipnetwork.Broadcast);
        Console.WriteLine("FirstUsable : {0}", ipnetwork.FirstUsable);
        Console.WriteLine("LastUsable : {0}", ipnetwork.LastUsable);
        Console.WriteLine("Usable : {0}", ipnetwork.Usable);
        Console.WriteLine("Cidr : {0}", ipnetwork.Cidr);

    }

`

Hope this helps.
Best regards
Luc

from ipnetwork.

Related Issues (20)

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.