Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to generate IP addresses from a range

Status
Not open for further replies.

lauraSatellite

Technical User
Jul 22, 2004
35
IE
Hi, i need to generate all ip addresses within a specified range. So given two values say 10.197.188.1 and 10.197.189.1 i need to generate all possible ip values in between.
If anyone has any ideas on how to do this I would appreciate it if you could let me know?
 
A starting point:
Function ip2num(ip)
Dim i, a, n
a = Split(ip, ".")
n = CDbl(0)
For i = 0 To UBound(a)
n = n * 256 + a(i)
Next
ip2num = n
End Function
Public Function num2ip(n)
Dim s, i, p, z
z = Int(n / 256)
s = Right("00000" & Hex(z), 6)
For i = 1 To 5 Step 2
p = p & Eval("&h" & Mid(s, i, 2)) & "."
Next
num2ip = p & Eval("&h" & Hex(n - 256 * z))
End Function
For x = ip2num("10.197.188.1") To ip2num("10.197.188.11")
ip = num2ip(x)
MsgBox ip
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top