Re: IP range to CIDR list VB6 utility?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: WinGuy (no_spam_at_nomail.bot)
Date: 09/20/04


Date: Mon, 20 Sep 2004 00:44:06 GMT


"Mike D Sutton" <EDais@mvps.org> wrote in message
news:OZPcZeonEHA.3876@TK2MSFTNGP15.phx.gbl...
> > Mike, is UnpackDWord something new with VB.Net? I can't find reference
to
> > it in Visual Studio for VB6 ...
>
> Check my post again..
> Hope this helps,
>
> Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: EDais@mvps.org
> WWW: http://www.mvps.org/EDais/

Heh. Ok, I'd been at it all night and my brain was really very tired.
Obviously not going to find a custom sub or function name identified in
Help!<grin>

Looked inet_addr() up with API-Guide (I have 3.7) and that's pretty nice,
actually, and thanks for the heads up. I see that it will take a dotted IP
string address and convert it to a binary equivalent enclosed within a long,
and that inet_ntoa() will do the reverse. This is nice clean code, much
better than what I'm doing now.

But I still have to use CIDR notation, which requires looking at an address
range using the full 32 bits. The reason is that the "/" value is the
pointer to the first bit of the 32 that does NOT match in both addresses
(reading left to right). If the string is not exactly 32 bits then that
value will be wrong.

So, while those 2 functions are of great utility as far as obtaining a
string value, i.e.:
' XLong=inet_addr("1.2.3.4")
' XString = trim(str(XLong))
the resultant binary string still must be padded with 0's on the left side
so that LEN(XString)=32.
' While LEN(XString<32)
' XString="0" & XString 'Not sure that really works as expected! I really
use 2 strings.
' Wend

The comment Jim made about the 2 addresses as in 1.2.3.0 (network) and
1.2.3.255 (broadcast) not being usable as a machine IP address is true, only
1.2.3.1 through 1.2.3.254 is usable, a total of 253 addresses, assuming a
netmask of 255.255.255.0 or the equivalent of 1.2.3.0/24 in CIDR notation. I
might be wrong, but I think any x.x.x.0 and x.x.x.255 address is not usable
as a machine address regardless of an assigned IP range.

The value range of an example 217.224.0.0 through 217.237.161.47 address
range can be represented by a LIST of netmasks that together define only
that address range and nothing else. But I have to use CIDR (/slash)
notation because my firewall rules require it, and it too requires building
a LIST in that notation format. Doing it any other way in that example would
result in exclusion of (or the addition of) addresses to the range. It's
not the conversion of addresses to binary that is causing me grief, it's the
building of the CIDR *list* that's driving me bonkers. :(

For the example range of 217.224.0.0 through 217.237.161.47 that network
range list would look like this:
217.224.154.0/13 'through 217.231.255.255
217.232.0.0/14 'through 217.235.255.255
217.236.0.0/16 'through 217.236.255.255
217.237.0.0/17 'through 217.237.127.255
217.237.128.0/19 'through 217.237.159.255
217.237.160.0/24 'through 217.237.160.255
217.237.161.0/27 'through 217.237.161.31
217.237.161.32/28 'through 217.237.161.47

or, using netmask to generate that exact same network range list:
217.224.154.0 'netmask 255.248.0.0
217.232.0.0 'netmask 255.252.0.0
217.236.0.0 'netmask 255.255.0.0
217.237.0.0 'netmask 255.255.128.0
217.237.128.0 'netmask 255.255.224.0
217.237.160.0 'netmask 255.255.255.0
217.237.161.0 'netmask 255.255.255.224
217.237.161.32 'netmask 255.255.255.240

Either way, only that exact 217.224.0.0 through 217.237.161.47 address range
would be acted upon, and nothing else. Using just 1 netmask would result in
either limiting or expanding the network address range - this case requires
8 iterations (this number of iterations varies depending on the address
range), and so I must calculate a list (and I must use CIDR notation for the
firewall). That's the part I need help with -- how to do the iteration to
produce the list. The logic is not as easy and as straight forward for me as
it seems that it should be!



Relevant Pages

  • Re: Countif for a string
    ... Thanks for both Bob and Harald for the quick response. ... > Hi Mike ... > Function ShouldImport(ByRef S As String) As Boolean ... >> I am importing a text file into excel line by line. ...
    (microsoft.public.excel.programming)
  • Re: Multiselect Listbox as qualifier for query
    ... That's correct, Mike. ... You can pass that kind of string in the ... Or you can re-write the SQL ... > other qualifiers within the individual query definitions. ...
    (microsoft.public.access.queries)
  • Re: Problem with AND &
    ... Mike wrote: ... I did not catch that since I changed the user records. ... But you're still passing a string as the first ... varbinary is a character type - basically the difference between that and varchar in MySQL is the binary types are case sensitive. ...
    (comp.lang.php)
  • Re: Bypassing WSE to add web reference
    ... on SoapClient (or SoapSender if you don't need request/response). ... "Mike" wrote in message ... > c, String className, String url, Binding binding) ... but poses a problem when you try to add a web reference ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: Problem with AND &
    ... Mike wrote: ... I did not catch that since I changed the user records. ... But you're still passing a string as the first ... before the signature lines or delete them all together. ...
    (comp.lang.php)