Solved

# Get ip addresses from a given range (192.168.2.1-192.168.2.255)

Posted on 2009-12-21
Medium Priority
473 Views
First off, let me say that I HAVE been looking for an example of how to do this, but surprisingly it is not a very popular topic\subject.

In VB.Net:

I need to get a list of IP addresses from a given range (192.168.2.1-192.168.2.255)

A VERY VAGUE EXAMPLE:

dim minimum_val as integer = textbox1.text
dim max_value as integer = textbox2.text

???
???
0
Question by:APag96
• 4
• 2

LVL 96

Accepted Solution

Bob Learned earned 200 total points
ID: 26105219
Here is what I use:

Sample usage:

``````Public Class IpAddressHelper

Dim list As New List(Of String)

For i As Long = n1 To n2
Next i
Return list
End Function

Dim parts() As String = ipAddress.Split(".")
Dim sum As Long
If parts.Length <> 4 Then
End If

For i As Integer = parts.Length - 1 To 0 Step -1
sum += (Int(parts(i)) Mod 256) * Math.Pow(256, 3 - i)
Next i
Return sum
End Function

Dim sb As New StringBuilder()
For i As Integer = 1 To 4
Dim factor As Integer = (256 ^ (4 - i))
Dim number As Long = ipAddressNumber \ factor
sb.Append(number & ".")
Next i
Return sb.ToString().TrimEnd(".")
End Function

End Class
``````
0

Author Comment

ID: 26108327
Looks good. I'll try this out and get back to you. Thanks.
0

Author Comment

ID: 26108637
Thank you very much! That is exactily what I was looking for. 50 points for you!
0

Author Closing Comment

ID: 31668790
Perfect.
0

LVL 96

Expert Comment

ID: 26108676
"I don't need no stinkin' points"  The "Thank you very much!" means more to me.
0

Author Comment

ID: 26114785
:) You deserve the points.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
###### Suggested Courses
Course of the Month16 days, 17 hours left to enroll