lundi 28 mars 2016

Generate a random IP address [duplicate]

This question already has an answer here:

I'm working on making a game called ' hacker '. It's allready in the name; You must hack. I now have a problem. I want to make something that you can find IP addresses, but every time I try it out, something goes wrong. I just wanted to random IP addresses, but I got this:

736.390.133.837
736.390.133.837
736.390.133.837
736.390.133.837
736.390.133.837
736.390.133.837
736.390.133.837
736.390.133.837
573.791.617.039
573.791.617.039

Here is my code:

For i As Integer = 1 To count
    Dim RN As New Random
    Dim x As Integer
    Dim IP As String
    Dim N1 As String
    x = RN.Next(0, 999)
    If x.ToString.Length = 1 Then
        N1 = "00" & x
    ElseIf x.ToString.Length = 2 Then
        N1 = "0" & x
    Else
        N1 = x
    End If

    Dim N2 As String
    x = RN.Next(0, 999)
    If x.ToString.Length = 1 Then
        N2 = "00" & x
    ElseIf x.ToString.Length = 2 Then
        N2 = "0" & x
    Else
        N2 = x
    End If

    Dim N3 As String
    x = RN.Next(0, 999)
    If x.ToString.Length = 1 Then
        N3 = "00" & x
    ElseIf x.ToString.Length = 2 Then
        N3 = "0" & x
    Else
        N3 = x
    End If

    Dim N4 As String
    x = RN.Next(0, 999)
    If x.ToString.Length = 1 Then
        N4 = "00" & x
    ElseIf x.ToString.Length = 2 Then
        N4 = "0" & x
    Else
        N4 = x
    End If

    IP = N1 & "." & N2 & "." & N3 & "." & N4
    cmdBox.Text &= vbCrLf & IP
Next




Aucun commentaire:

Enregistrer un commentaire