<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: IPv4 subnet math with VbScript</title>
	<atom:link href="http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/</link>
	<description></description>
	<lastBuildDate>Thu, 09 Sep 2010 08:18:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Robin</title>
		<link>http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/comment-page-1/#comment-10</link>
		<dc:creator>Robin</dc:creator>
		<pubDate>Thu, 03 Dec 2009 10:02:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=270#comment-10</guid>
		<description>Beautiful functions!
Thumbs up!

:)</description>
		<content:encoded><![CDATA[<p>Beautiful functions!<br />
Thumbs up!</p>
<p>:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gavin Mackenzie</title>
		<link>http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/comment-page-1/#comment-9</link>
		<dc:creator>Gavin Mackenzie</dc:creator>
		<pubDate>Sat, 12 Sep 2009 15:42:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=270#comment-9</guid>
		<description>Great work. functions work perfectly and have saved me a heap of work.

Awesome :)</description>
		<content:encoded><![CDATA[<p>Great work. functions work perfectly and have saved me a heap of work.</p>
<p>Awesome :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/comment-page-1/#comment-8</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Fri, 11 Sep 2009 08:16:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=270#comment-8</guid>
		<description>Realy great collection of scripts.
Right the scripts I was looking for.
Thanks.</description>
		<content:encoded><![CDATA[<p>Realy great collection of scripts.<br />
Right the scripts I was looking for.<br />
Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/comment-page-1/#comment-7</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Fri, 27 Mar 2009 16:37:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=270#comment-7</guid>
		<description>Thanks for these functions.  I used them, and the information on some of your other pages to write the following functions:
[code lang=&quot;vb&quot;]
Function GetNumberOfAvailableHostAddresses(nMaskLength)
    Dim nHosts, nAvailableBits
    nHosts = -1
    &#039;wscript.echo
    nAvailableBits = 32 - nMaskLength

    &#039;wscript.echo nAvailableBits
    &#039;Number of Addresses Available for Hosts in Subnet = 2(32 - Number of Masked Bits) - 2

    nHosts = (2 ^ nAvailableBits) - 2

    GetNumberOfAvailableHostAddresses = nHosts
End Function

Function GetAllHostAddresses(sNetAddress, sMaskLength)
    Dim oAllIPs
    Dim sBroadcast, sNetwork
    Dim arrOctets
    Dim nIndexOct4, nIndexOct3, nIndexOct2, nIndexOct1

    &#039;Add all IPS to dictionary object
    Set oAllIPs = CreateObject(&quot;Scripting.Dictionary&quot;)

    &#039;Network address is low address, Broadcast address is high address
    sNetwork = CalcNetworkAddress(sNetAddress, sMaskLength)
    sBroadcast = CalcBroadcastAddress(strIP, strMask)

    arrNetwork = Split(sNetwork, &quot;.&quot;)
    arrBroadcast = Split(sBroadcast, &quot;.&quot;)

    For nIndexOct1 = arrNetwork(0) To arrBroadcast(0)
        For nIndexOct2 = arrNetwork(1) To arrBroadcast(1)
            For nIndexOct3 = arrNetwork(2) To arrBroadcast(2)
                For nIndexOct4 = arrNetwork(3) To arrBroadcast(3)
                    &#039;Wscript.echo nIndexOct1 &amp; &quot;.&quot; &amp; nIndexOct2 &amp; &quot;.&quot; &amp; nIndexOct3 &amp; &quot;.&quot; &amp; nIndexOct4
                    oAllIPs.add nIndexOct1 &amp; &quot;.&quot; &amp; nIndexOct2 &amp; &quot;.&quot; &amp; nIndexOct3 &amp; &quot;.&quot; &amp; nIndexOct4, &quot;&quot;
                Next
            Next
        Next
    Next

    Set GetAllHostAddresses = oAllIPs
End Function
[/code]</description>
		<content:encoded><![CDATA[<p>Thanks for these functions.  I used them, and the information on some of your other pages to write the following functions:</p>
<pre class="brush: vb;">
Function GetNumberOfAvailableHostAddresses(nMaskLength)
    Dim nHosts, nAvailableBits
    nHosts = -1
    'wscript.echo
    nAvailableBits = 32 - nMaskLength

    'wscript.echo nAvailableBits
    'Number of Addresses Available for Hosts in Subnet = 2(32 - Number of Masked Bits) - 2

    nHosts = (2 ^ nAvailableBits) - 2

    GetNumberOfAvailableHostAddresses = nHosts
End Function

Function GetAllHostAddresses(sNetAddress, sMaskLength)
    Dim oAllIPs
    Dim sBroadcast, sNetwork
    Dim arrOctets
    Dim nIndexOct4, nIndexOct3, nIndexOct2, nIndexOct1

    'Add all IPS to dictionary object
    Set oAllIPs = CreateObject(&quot;Scripting.Dictionary&quot;)

    'Network address is low address, Broadcast address is high address
    sNetwork = CalcNetworkAddress(sNetAddress, sMaskLength)
    sBroadcast = CalcBroadcastAddress(strIP, strMask)

    arrNetwork = Split(sNetwork, &quot;.&quot;)
    arrBroadcast = Split(sBroadcast, &quot;.&quot;)

    For nIndexOct1 = arrNetwork(0) To arrBroadcast(0)
        For nIndexOct2 = arrNetwork(1) To arrBroadcast(1)
            For nIndexOct3 = arrNetwork(2) To arrBroadcast(2)
                For nIndexOct4 = arrNetwork(3) To arrBroadcast(3)
                    'Wscript.echo nIndexOct1 &amp;amp; &quot;.&quot; &amp;amp; nIndexOct2 &amp;amp; &quot;.&quot; &amp;amp; nIndexOct3 &amp;amp; &quot;.&quot; &amp;amp; nIndexOct4
                    oAllIPs.add nIndexOct1 &amp;amp; &quot;.&quot; &amp;amp; nIndexOct2 &amp;amp; &quot;.&quot; &amp;amp; nIndexOct3 &amp;amp; &quot;.&quot; &amp;amp; nIndexOct4, &quot;&quot;
                Next
            Next
        Next
    Next

    Set GetAllHostAddresses = oAllIPs
End Function
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/comment-page-1/#comment-6</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Mon, 01 Dec 2008 14:06:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=270#comment-6</guid>
		<description>Hi Jon,

Sorry for the delay in getting back to you, I&#039;ve been on holiday so a bit out of touch.

The functions return the correct value for me, did you also include the ConvertIPToBinary and ConvertBinIPToDecimal?

Normally you would use the function something like this:

strNetAddr = CalcNetworkAddress(strIP, strMask)
Or
WScript.Echo CalcNetworkAddress(strIP, strMask)

Chris</description>
		<content:encoded><![CDATA[<p>Hi Jon,</p>
<p>Sorry for the delay in getting back to you, I&#8217;ve been on holiday so a bit out of touch.</p>
<p>The functions return the correct value for me, did you also include the ConvertIPToBinary and ConvertBinIPToDecimal?</p>
<p>Normally you would use the function something like this:</p>
<p>strNetAddr = CalcNetworkAddress(strIP, strMask)<br />
Or<br />
WScript.Echo CalcNetworkAddress(strIP, strMask)</p>
<p>Chris</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/comment-page-1/#comment-5</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Mon, 01 Dec 2008 13:35:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=270#comment-5</guid>
		<description>Hey Franklin,

Thanks for the contribution :)

All code is intended to be public domain, I&#039;ll post an explicit statement to that effect somewhere.

Chris</description>
		<content:encoded><![CDATA[<p>Hey Franklin,</p>
<p>Thanks for the contribution :)</p>
<p>All code is intended to be public domain, I&#8217;ll post an explicit statement to that effect somewhere.</p>
<p>Chris</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Franklin Piat</title>
		<link>http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/comment-page-1/#comment-4</link>
		<dc:creator>Franklin Piat</dc:creator>
		<pubDate>Sat, 15 Nov 2008 10:23:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=270#comment-4</guid>
		<description>Thanks a lot for these scripts. I them in one of my script.

I have written two extra functions (based on yours), which returns the first and last IP address of a subnet. (usefull for some tools).

I place my contribution in public domain.
BTW, Could you clarify the license of your script (typically Public domain, BSD  license, or GPL license).
[code lang=&quot;vb&quot;]
&#039; **** Calculate the first usable address of a subnet ****
&#039;
&#039; Note that this function includes calls to both ConvertIPToBinary and ConvertBinIPToDecimal.
Function CalcRangeStart(strIP, strMask)
  &#039; Generates the Network Address from the IP and Mask

  Dim arrOctets
  Dim strBinIP, strBinMask, strIPBit, strMaskBit, strBinStart
  Dim intOctet, i, j

  &#039; Conversion of IP and Mask to binary
  strBinIP = ConvertIPToBinary(strIP)
  strBinMask = ConvertIPToBinary(strMask)

  &#039; Bitwise AND operation (except for the dot)
  For i = 1 to Len(strBinIP)
    strIPBit = Mid(strBinIP, i, 1)
    strMaskBit = Mid(strBinMask, i, 1)

    If strIPBit = &quot;1&quot; And strMaskBit = &quot;1&quot; Then
      strBinStart = strBinStart &amp; &quot;1&quot;
    ElseIf strIPBit = &quot;.&quot; Then
      strBinStart = strBinStart &amp; strIPBit
    Else
      If i = Len(strBinIP) Then
        strBinStart = strBinStart &amp; &quot;1&quot;
      Else
        strBinStart = strBinStart &amp; &quot;0&quot;
      End If
    End If
  Next

  &#039; Conversion of Binary IP to Decimal
  CalcRangeStart = ConvertBinIPToDecimal(strBinStart)
End Function


&#039; **** Calculate the last usable address of a subnet ****
&#039;
&#039; Note that this function includes calls to both ConvertIPToBinary and ConvertBinIPToDecimal.
Function CalcRangeEnd(strIP, strMask)
  &#039; Generates the Network Address from the IP and Mask

  Dim arrOctets
  Dim strBinIP, strBinMask, strIPBit, strMaskBit, strBinEnd
  Dim intOctet, i, j

  &#039; Conversion of IP and Mask to binary
  strBinIP = ConvertIPToBinary(strIP)
  strBinMask = ConvertIPToBinary(strMask)

  &#039; Bitwise AND operation (except for the dot)
  For i = 1 to Len(strBinIP)
    strIPBit = Mid(strBinIP, i, 1)
    strMaskBit = Mid(strBinMask, i, 1)

    If strMaskBit = &quot;1&quot; Then
      strBinEnd = strBinEnd &amp; strIPBit
    ElseIf strIPBit = &quot;.&quot; Then
      strBinEnd = strBinEnd &amp; strIPBit
    Else
      If i = Len(strBinIP) Then
        strBinEnd = strBinEnd &amp; &quot;0&quot;
      Else
        strBinEnd = strBinEnd &amp; &quot;1&quot;
      End If
    End If
  Next

  &#039; Conversion of Binary IP to Decimal
  CalcRangeEnd = ConvertBinIPToDecimal(strBinEnd)
End Function
[/code]</description>
		<content:encoded><![CDATA[<p>Thanks a lot for these scripts. I them in one of my script.</p>
<p>I have written two extra functions (based on yours), which returns the first and last IP address of a subnet. (usefull for some tools).</p>
<p>I place my contribution in public domain.<br />
BTW, Could you clarify the license of your script (typically Public domain, BSD  license, or GPL license).</p>
<pre class="brush: vb;">
' **** Calculate the first usable address of a subnet ****
'
' Note that this function includes calls to both ConvertIPToBinary and ConvertBinIPToDecimal.
Function CalcRangeStart(strIP, strMask)
  ' Generates the Network Address from the IP and Mask

  Dim arrOctets
  Dim strBinIP, strBinMask, strIPBit, strMaskBit, strBinStart
  Dim intOctet, i, j

  ' Conversion of IP and Mask to binary
  strBinIP = ConvertIPToBinary(strIP)
  strBinMask = ConvertIPToBinary(strMask)

  ' Bitwise AND operation (except for the dot)
  For i = 1 to Len(strBinIP)
    strIPBit = Mid(strBinIP, i, 1)
    strMaskBit = Mid(strBinMask, i, 1)

    If strIPBit = &quot;1&quot; And strMaskBit = &quot;1&quot; Then
      strBinStart = strBinStart &amp;amp; &quot;1&quot;
    ElseIf strIPBit = &quot;.&quot; Then
      strBinStart = strBinStart &amp;amp; strIPBit
    Else
      If i = Len(strBinIP) Then
        strBinStart = strBinStart &amp;amp; &quot;1&quot;
      Else
        strBinStart = strBinStart &amp;amp; &quot;0&quot;
      End If
    End If
  Next

  ' Conversion of Binary IP to Decimal
  CalcRangeStart = ConvertBinIPToDecimal(strBinStart)
End Function

' **** Calculate the last usable address of a subnet ****
'
' Note that this function includes calls to both ConvertIPToBinary and ConvertBinIPToDecimal.
Function CalcRangeEnd(strIP, strMask)
  ' Generates the Network Address from the IP and Mask

  Dim arrOctets
  Dim strBinIP, strBinMask, strIPBit, strMaskBit, strBinEnd
  Dim intOctet, i, j

  ' Conversion of IP and Mask to binary
  strBinIP = ConvertIPToBinary(strIP)
  strBinMask = ConvertIPToBinary(strMask)

  ' Bitwise AND operation (except for the dot)
  For i = 1 to Len(strBinIP)
    strIPBit = Mid(strBinIP, i, 1)
    strMaskBit = Mid(strBinMask, i, 1)

    If strMaskBit = &quot;1&quot; Then
      strBinEnd = strBinEnd &amp;amp; strIPBit
    ElseIf strIPBit = &quot;.&quot; Then
      strBinEnd = strBinEnd &amp;amp; strIPBit
    Else
      If i = Len(strBinIP) Then
        strBinEnd = strBinEnd &amp;amp; &quot;0&quot;
      Else
        strBinEnd = strBinEnd &amp;amp; &quot;1&quot;
      End If
    End If
  Next

  ' Conversion of Binary IP to Decimal
  CalcRangeEnd = ConvertBinIPToDecimal(strBinEnd)
End Function
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Lundfelt</title>
		<link>http://www.indented.co.uk/index.php/2008/10/21/vbscript-subnet-math/comment-page-1/#comment-3</link>
		<dc:creator>Jon Lundfelt</dc:creator>
		<pubDate>Tue, 11 Nov 2008 19:34:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=270#comment-3</guid>
		<description>This is all very impressive. I am able to get most of these to work for what I need, which is fantastic. However, I cannot for the life of me get the &#039;Calculate the subnet network address&#039; function(s) to work.

It just returns a string like so;

00001010.00011110.00110011.00111110 11111111.11111111.11111111.00000000 0 0 00001010.00011110.00110011.00000000

I am trying to get the network address (e.g. 192.168.0/24) from the IP address and Subnet mask;


strIP = &quot;192.168.0.100&quot;
strMask = &quot;255.255.255.0&quot;

CalcNetworkAddress strIP, strMask

I am sure I am missing something.

TIA !
Jon</description>
		<content:encoded><![CDATA[<p>This is all very impressive. I am able to get most of these to work for what I need, which is fantastic. However, I cannot for the life of me get the &#8216;Calculate the subnet network address&#8217; function(s) to work.</p>
<p>It just returns a string like so;</p>
<p>00001010.00011110.00110011.00111110 11111111.11111111.11111111.00000000 0 0 00001010.00011110.00110011.00000000</p>
<p>I am trying to get the network address (e.g. 192.168.0/24) from the IP address and Subnet mask;</p>
<p>strIP = &#8220;192.168.0.100&#8243;<br />
strMask = &#8220;255.255.255.0&#8243;</p>
<p>CalcNetworkAddress strIP, strMask</p>
<p>I am sure I am missing something.</p>
<p>TIA !<br />
Jon</p>
]]></content:encoded>
	</item>
</channel>
</rss>
