1

我想生成两个 IP 开始 IP 和 IP 之间的所有 IP 地址列表

 textbox1.text = startiprange = "192.168.0.0"
 textbox2.text = endiprange = "192.168.255.255"

如何用简单的方法做到这一点?

4

1 回答 1

4

尝试这个

    'start and end ip address
    Dim startiprange As Net.IPAddress = Net.IPAddress.Parse("192.168.0.0")
    Dim endiprange As Net.IPAddress = Net.IPAddress.Parse("192.168.255.255")

    'reverse address bytes for conversion to integer
    Dim strtip() As Byte = startiprange.GetAddressBytes
    Array.Reverse(strtip)
    Dim endip() As Byte = endiprange.GetAddressBytes
    Array.Reverse(endip)

    'convert
    Dim ips As UInt32 = BitConverter.ToUInt32(strtip, 0)
    Dim ipe As UInt32 = BitConverter.ToUInt32(endip, 0)

    'then loop from start to end
    For anip As UInt32 = ips To ipe
        'convert to bytes
        Dim ipbyt() As Byte = BitConverter.GetBytes(anip)
        'reverse and create ip address
        Array.Reverse(ipbyt)
        Dim ipaddr As New Net.IPAddress(ipbyt)
        Debug.WriteLine(ipaddr.ToString)
    Next
于 2013-04-11T18:18:42.077 回答