locked
Script that converts an IP address and cidr to a 3 octed network ID RRS feed

  • Question

  • Hi guys,

    I've made a WMI/powershell script that get's me an IP address and the cidr. 192.168.0.2/23.

    Can anybody show me an method that has as input an IP adress and a cidr notation and gives me back an 3 octet networkID (192.168.0).

    Kind regards,

    André

    Thursday, October 5, 2017 9:03 AM

Answers

  • This does the math:

    A NetID has 4 octets always.

    When net is divided below 24 the last octet shows its importance:

    Download module here: https://github.com/lduchosal/ipnetwork

    or retrieve PS module version:

    find-module CWJIPNetwork | Import-Module


    \_(ツ)_/



    • Edited by jrv Thursday, October 5, 2017 10:48 AM
    • Marked as answer by Borgy333 Thursday, October 5, 2017 10:59 AM
    Thursday, October 5, 2017 10:39 AM
  • Because you have to download a module first to your powershell development server to find it.

    You can run the PS line on any system with PowerShell 5 or later.  The module can be easily copied anywhere with a simple copy command.

    The DLL can be loaded using Add-Type.


    \_(ツ)_/

    • Marked as answer by Borgy333 Thursday, October 5, 2017 12:17 PM
    Thursday, October 5, 2017 12:02 PM

All replies

  • This does the math:

    A NetID has 4 octets always.

    When net is divided below 24 the last octet shows its importance:

    Download module here: https://github.com/lduchosal/ipnetwork

    or retrieve PS module version:

    find-module CWJIPNetwork | Import-Module


    \_(ツ)_/



    • Edited by jrv Thursday, October 5, 2017 10:48 AM
    • Marked as answer by Borgy333 Thursday, October 5, 2017 10:59 AM
    Thursday, October 5, 2017 10:39 AM
  • Cool man, thanks for the examples.
    Thursday, October 5, 2017 10:59 AM
  • Hi Jrv,

    Where do i find the powershell module. I've searched on GitHub but i didn't find it.

    Kind regards,

    André

    Thursday, October 5, 2017 11:30 AM
  • Just click the download button.

    \_(ツ)_/

    Thursday, October 5, 2017 11:32 AM
  • Hi, thanks. And yes we got a 4 octet network ;-).
    You placed a link to github which brings me to the C# version and binaries. When i download the release (*.zip) file i get the c# exectuble not the powershell module.

    So where can i download the powershell module. Maybe i've overlooked something.


    • Edited by Borgy333 Thursday, October 5, 2017 11:41 AM
    Thursday, October 5, 2017 11:41 AM
  • So why don't you use the provided Powershell command line?

    find-module CWJIPNetwork | Import-Module


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, October 5, 2017 11:54 AM
  • Because you have to download a module first to your powershell development server to find it.
    Thursday, October 5, 2017 11:56 AM
  • Because you have to download a module first to your powershell development server to find it.

    You can run the PS line on any system with PowerShell 5 or later.  The module can be easily copied anywhere with a simple copy command.

    The DLL can be loaded using Add-Type.


    \_(ツ)_/

    • Marked as answer by Borgy333 Thursday, October 5, 2017 12:17 PM
    Thursday, October 5, 2017 12:02 PM
  • Sorry we work in an Enterprise environment and we got 2012 R2, 2016 and 2008 r2

    I still do some tasks on 2008 R2 that's why i did not find it.

    And i thought this was a custom module, that's why. Got it working now.

    Thursday, October 5, 2017 12:20 PM