微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VB.NET产生指定范围内的IP地址列表

给定一个IP地址开头和结尾,返回在此范围内的所有IP地址列表,VB.Net实现,可以很容易的转换成C#代码

    'start and end ip address ,code from www.sharejs.com
    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
//该代码片段来自于: http://www.sharejs.com/codes/asp/8680

原文转自:脚本分享http://www.sharejs.com/codes/asp/8680

原文地址:https://www.jb51.cc/vb/258509.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐