# of IPs in IP range Function?
# of IPs in IP range Function?
# of IPs in IP range Function?
# of IPs in IP range Function?
# of IPs in IP range Function?
# of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function?
# of IPs in IP range Function? # of IPs in IP range Function?
# of IPs in IP range Function?
Go Back  Xtreme Visual Basic Talk > > > # of IPs in IP range Function?


Reply
 
Thread Tools Display Modes
  #1  
Old 11-07-2002, 11:55 AM
AcidicChip
Guest
 
Posts: n/a
Question # of IPs in IP range Function?


I need a function that'll count how many IPs are in a range...

eg: 192.168.1.100 - 192.168.1.150 is 50 IPs
eg: 192.168.1.100 - 192.168.5.235 is ???? IPs

Can someone give me a function for that? Thanks!

Last edited by AcidicChip; 11-08-2002 at 09:16 AM.
Reply With Quote
  #2  
Old 11-08-2002, 09:15 AM
AcidicChip
Guest
 
Posts: n/a
Default

No one knows the answer?
Reply With Quote
  #3  
Old 11-08-2002, 09:30 AM
Cyberax's Avatar
Cyberax Cyberax is offline
Centurion
 
Join Date: Sep 2002
Location: Manchester, UK
Posts: 155
Default

You can use the sub net to count ip addresses in a range or do you want an algorithm that will count in any given range I.E.

195.1.1.0 > 195.1.1.100 = 100

????

Ian
__________________
Why do croutons come in airtight packages? Aren`t they just stale bread to begin with?
Reply With Quote
  #4  
Old 11-08-2002, 09:36 AM
AcidicChip
Guest
 
Posts: n/a
Default

I'm looking for something that would work like...

NumberOfIPs([Start IP],[End IP])

eg. NumberOfIPs("192.168.1.100","192.168.5.253")
returns 1273

Can anyone help? Thanks!
Reply With Quote
  #5  
Old 11-08-2002, 09:40 AM
Cyberax's Avatar
Cyberax Cyberax is offline
Centurion
 
Join Date: Sep 2002
Location: Manchester, UK
Posts: 155
Default

what calculation did you use to work that out ?
__________________
Why do croutons come in airtight packages? Aren`t they just stale bread to begin with?
Reply With Quote
  #6  
Old 11-08-2002, 09:47 AM
AcidicChip
Guest
 
Posts: n/a
Default

I just did

192.168.1.100
192.168.5.253
\/\/\/\/\/\/\/\/\/

192.168.5.253
192.168.1.100
------------------
0.0.4.153


255 x 4 = 1020
1020 + 153 = 1173

The one I did in my previous post was wrong... Hehe, I dunno if even this one is right... That's why I need a function.
Reply With Quote
  #7  
Old 11-11-2002, 11:54 AM
AcidicChip
Guest
 
Posts: n/a
Default

So can anyone help here?
Reply With Quote
  #8  
Old 11-11-2002, 12:39 PM
orufet's Avatar
orufet orufet is offline
Paranoid Coder

Retired Leader
 
Join Date: Mar 2001
Location: Canada
Posts: 2,716
Default

Well, you seem to have an approach to do it...why not just write that out in VB code in your own function? Often, the hardest part to programming is solving a problem; you've already done that.
Reply With Quote
  #9  
Old 11-11-2002, 01:08 PM
AcidicChip
Guest
 
Posts: n/a
Default

well I can only calulate 1.1.xxx.xxx range... i need it written fro xxx.xxx.xxx.xxx range. Maybe you can use my formula to get the remaining x.x solved? I'm guessing it's mainly done in 255 powers, but i dunno.
Reply With Quote
  #10  
Old 11-11-2002, 04:00 PM
ChiefRedBull's Avatar
ChiefRedBull# of IPs in IP range Function? ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

Think about it like this:

Each octet in the IP represents 256 possible values. So if you
have one octet, you have 256 possible values. If you have 2
octets then you have 256^2 possible values, 3 octets you have
256^3 and so on.

Your function would be something like this:
Code:
' split both IPs into octets ' for each octet in sStart ' if sFinish is greater ' work out the difference ' if this octet is not the last one ' multiply the difference by 256 ' add to the total
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #11  
Old 11-11-2002, 05:05 PM
AcidicChip
Guest
 
Posts: n/a
Default

hummm... Me = Newbie Then Make Function For Me

Me.Intellegence < 1

Reply With Quote
  #12  
Old 11-12-2002, 04:51 AM
ChiefRedBull's Avatar
ChiefRedBull# of IPs in IP range Function? ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

Code:
If Me.MakeFunctionForYou() Then Call You.PayMe (vbLotsOfMoney) End If
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #13  
Old 11-12-2002, 05:14 AM
Cyberax's Avatar
Cyberax Cyberax is offline
Centurion
 
Join Date: Sep 2002
Location: Manchester, UK
Posts: 155
Default

If Pseudo.Code = VBComplete then
Problem.value = (problem.value * 50) / 100
Call CreateVbCode
Problem.Value = 0
endif
__________________
Why do croutons come in airtight packages? Aren`t they just stale bread to begin with?
Reply With Quote
  #14  
Old 11-12-2002, 06:29 AM
AcidicChip
Guest
 
Posts: n/a
Default

ChiefRedBull, I'll paypal you $20 if you write the function for me
Reply With Quote
  #15  
Old 11-12-2002, 07:51 AM
orufet's Avatar
orufet orufet is offline
Paranoid Coder

Retired Leader
 
Join Date: Mar 2001
Location: Canada
Posts: 2,716
Default

Reply With Quote
  #16  
Old 11-15-2002, 06:27 AM
Garmour's Avatar
Garmour# of IPs in IP range Function? Garmour is offline
Back for a little while..

Retired Leader
* Expert *
 
Join Date: Oct 2002
Location: Behind you.....Boo
Posts: 2,199
Default

ok, I had thought of another way to solve this.
simply convert each byte to hex
ie 1.1.1.1 becomes &H01010101
255.255.255.255 becomes &HFFFFFFFF
then subtract them

But, I can't get any data type to do the subtractions.

I have two strings
hexval1 = "&H01010101"
hexval2 = "&HFFFFFFFF"

text1.text = cdec(hexval2) - cdec(hexval1)

doesn't work
No matter how I try to force hexval2 it always evaluates to -1
__________________

....but then, what would I know ?
Reply With Quote
  #17  
Old 11-15-2002, 07:34 AM
AcidicChip
Guest
 
Posts: n/a
Default

Man, I hate not being able to get this right.
Reply With Quote
  #18  
Old 11-15-2002, 08:55 AM
james220557
Guest
 
Posts: n/a
Default

Could I suggest this one.
I kept the code as simple as possible to show the method I used. (language purists will forgive me). You may optimize it for sure.

I tested it with the call NumberOfIPs("192.168.1.100", "192.168.5.253") and got 1177 as you calculate.

Hope this helps

james220557

Code:
Function NumberOfIPs(Start_IP As String, End_IP As String) As Variant Dim SearchStr As String Dim initPos As Integer Dim finalPos As Integer Dim Index As Integer Dim IP_init As Variant Dim IP_final As Variant Dim IP_number As Variant 'parses for start IP SearchStr = Start_IP GoSub ParseIP IP_init = IP_number 'parses for final IP SearchStr = End_IP GoSub ParseIP IP_final = IP_number NumberOfIPs = IP_final - IP_init Exit Function ParseIP: Index = 0 initPos = 1 ' initialze pointer and Index counter IP_number = 0 ' initialize it to zero Do Until Index > 3 nextPos = InStr(initPos, SearchStr, ".") Select Case Index Case 0 IP_number = Mid(SearchStr, 1, nextPos) * (256 ^ 3) + IP_number Case 1 IP_number = Mid(SearchStr, initPos, nextPos - initPos) * (256 ^ 2) + IP_number Case 2 IP_number = Mid(SearchStr, initPos, nextPos - initPos) * (256 ^ 1) + IP_number Case 3 IP_number = Mid(SearchStr, initPos, Len(SearchStr) - initPos + 1) * (256 ^ 0) + IP_number End Select Index = Index + 1 initPos = nextPos + 1 Loop Return End Function
Edit: Added VB tags. Chief

Last edited by ChiefRedBull; 11-17-2002 at 03:02 PM.
Reply With Quote
  #19  
Old 11-15-2002, 09:03 AM
AcidicChip
Guest
 
Posts: n/a
Default

It's people like you that bring me up from a bad day, you rock. Thanx james.
Reply With Quote
  #20  
Old 11-17-2002, 03:15 PM
ChiefRedBull's Avatar
ChiefRedBull# of IPs in IP range Function? ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

Language purist: Eurgh.. GoSub and Variants, plus obviously no
Option Explicit (nextPos was undefined).

Here's my attempt:
Code:
Private Function CountIPs(ByVal sStartIP As String, _ ByVal sFinishIP As String) As Long Dim i As Long Dim lDiff As Long Dim lTotal As Long Dim sStart() As String Dim sFinish() As String ' split both IPs into octets sStart = Split(sStartIP, ".") sFinish = Split(sFinishIP, ".") ' for each octet in sStart For i = 0 To 3 ' if sFinish is greater If CLng(sFinish(i)) > CLng(sStart(i)) Then ' work out the difference lDiff = CLng(sFinish(i)) - CLng(sStart(i)) ' calculate this from the octets position lDiff = lDiff * (256 ^ (3 - i)) ' add to the total lTotal = lTotal + lDiff End If Next i ' return CountIPs = lTotal End Function
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
# of IPs in IP range Function?
# of IPs in IP range Function?
# of IPs in IP range Function? # of IPs in IP range Function?
# of IPs in IP range Function?
# of IPs in IP range Function?
# of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function? # of IPs in IP range Function?
# of IPs in IP range Function?
# of IPs in IP range Function?
 
# of IPs in IP range Function?
# of IPs in IP range Function?
 
-->