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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值