生成随机IP地址

时间:2016-03-28 08:53:07

标签: vb.net visual-studio-2010 random

我正在制作一款名为'黑客'。它已经在名字中了;你必须破解。我现在有一个问题。我想制作一些你可以找到IP地址的东西,但每次尝试都会出现问题。我只是想随机分配IP地址,但我得到了这个:

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

这是我的代码:

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

0 个答案:

没有答案