Jump to content
Sign in to follow this  
vickerps

Creating IPs

Recommended Posts

vickerps

Hi has anyone wrote a script that will calculate IP by a given number

for example 10.0.0.1 + 64 = 10.0.0.65 +64 = 10.0.0.129 +64 = 10.0.0.193

at this point i need it to start again but to increment the third octet to 1

for example 10.0.1.1 + 64 = 10.0.1.65 +64 = 10.0.1.129 +64 = 10.0.1.193

etc ,etc

Share this post


Link to post
Share on other sites
spudw2k

Here's something I threw together. It's not perfect, but may do what you want. It will only increase the 3rd and 4th octets.

#include <Array.au3>

;IPRange(start ip address,end ip address,step)
$result = IPRange("10.0.0.1","10.0.1.254",64)
_ArrayDisplay($result)

Func IPRange($ipAddr,$lastip,$step = 1)
    Dim $iparr[1]
    $ip = StringSplit($ipAddr,".")
    $orgip = StringSplit($ipAddr,".")
    $endip = StringSplit($lastip,".")
    If $ip[0] = 0 Or $endip[0] = 0 Then Return 0
    Do
        Do
            Do
                Do
                    _ArrayAdd($iparr,$ip[1] & "." & $ip[2] & "." & $ip[3] & "." & $ip[4])
                    $ip[4] += $step
                Until $ip[4] > 254
                $ip[4] = $orgip[4]
                $ip[3] += 1
            Until $ip[3] > $endip[3]
        Until $ip[2] >= $endip[2] And $ip[3] >= $endip[3]
    Until $ip[1] >= $endip[1] And $ip[2] >= $endip[2] And $ip[3] >= $endip[3]
    $iparr[0] = UBound($iparr) - 1
    Return $iparr
EndFunc
Edited by spudw2k

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×