• Status: Solved
• Priority: Medium
• Security: Public
• Views: 484

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

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
APag96
• 4
• 2
1 Solution

Commented:
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 Commented:
Looks good. I'll try this out and get back to you. Thanks.
0

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

Author Commented:
Perfect.
0

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

Author Commented:
:) You deserve the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.