Jump to content
Sign in to follow this  

Creating IPs

Recommended Posts


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

for example + 64 = +64 = +64 =

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

for example + 64 = +64 = +64 =

etc ,etc

Share this post

Link to post
Share on other sites

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("","",64)

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
                    _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
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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.