IP Addresses

Local time
Today, 02:42
Joined
Sep 29, 2003
Messages
25
Hi this may be a hard one. i need to create 192.168.999.999 ip addresses so i dont know where to start. if i typed them all in it may take years. so can anyone help. e.g a button that will create them. it has to start with 192.192 then 000.001 many thanks for any help


daniel
 
Here's some ADO code to create the IPs you need. It assumes you have a table called tblIP with a text field called "IP". If you're using Access 97 or DAO the code can be altered for that.

Code:
Sub CreateIPs()
Dim rst As ADODB.Recordset
Dim intLoop3 As Integer, intLoop4 As Integer
Dim strIP As String

    'Set initial values
    intLoop3 = 0
    intLoop4 = 1
    strIP = "192.168."
    
    Set rst = New ADODB.Recordset
    rst.Open "tblIP", CurrentProject.Connection, adOpenForwardOnly, adLockOptimistic
    
    Do Until intLoop3 > 999
        Do Until intLoop4 > 999
            rst.AddNew
            rst.Fields("IP") = strIP & _
                Format(intLoop3, "000") & "." & _
                Format(intLoop4, "000")
            intLoop4 = intLoop4 + 1
        Loop
        intLoop4 = 1
        intLoop3 = intLoop3 + 1
    Loop
    
    'Update the recordset
    rst.Update
    
    Set rst = Nothing

End Sub
 
Daniel,

You might be a tad too ambitious. Here's the range of addresses you likely need:

192.168.0.1-255
192.168.1.0-255
192.168.2.0-255
192.168.3.0-255
192.168.4.0-255

up to

192.168.255.254

Anything above 255 in any of the four parts of an IP address is invalid. It looks like DCX93's code can be easily adjusted to reflect this.

Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom