Beispiel #1
0
        protected void GetRange(string StartIp, string EndIp)
        {
            var ipTool = new IPTool();
            int start = ipTool.IPToInt(StartIp);
            int end = ipTool.IPToInt(EndIp);

            for (int i = start; i <= end; i++)
            {
                byte[] bytes = BitConverter.GetBytes(i);
                WriteObject(new IPAddress(new[] { bytes[3], bytes[2], bytes[1], bytes[0] }));
            }
        }
Beispiel #2
0
        protected void GetIPRangeByCIDR(string CIDRNet)
        {
            string[] cidr   = CIDRNet.Split('/');
            var      ipTool = new IPTool();

            // Parse values for network.
            int ip        = ipTool.IPToInt(cidr[0]);
            int bits      = Convert.ToInt32(cidr[1]);
            int mask      = ~((1 << (32 - bits)) - 1);
            int network   = ip & mask;
            int broadcast = network + ~mask;
            int startIP   = network + 1;
            int endIP     = broadcast - 1;
            int usableIps = (bits > 30) ? 0 : (broadcast - network - 1);

            // Generate list
            for (int i = startIP; i <= endIP; i++)
            {
                byte[] bytes = BitConverter.GetBytes(i);
                WriteObject(new IPAddress(new[] { bytes[3], bytes[2], bytes[1], bytes[0] }));
            }
        }
Beispiel #3
0
        protected void GetIPRangeByCIDR(string CIDRNet)
        {
            string[] cidr = CIDRNet.Split('/');
            var ipTool = new IPTool();

            // Parse values for network.
            int ip = ipTool.IPToInt(cidr[0]);
            int bits = Convert.ToInt32(cidr[1]);
            int mask = ~((1 << (32 - bits)) - 1);
            int network = ip & mask;
            int broadcast = network + ~mask;
            int startIP = network + 1;
            int endIP = broadcast - 1;
            int usableIps = (bits > 30) ? 0 : (broadcast - network - 1);
           
            // Generate list
            for (int i = startIP; i <= endIP; i++)
            {
                byte[] bytes = BitConverter.GetBytes(i);
                WriteObject(new IPAddress(new[] { bytes[3], bytes[2], bytes[1], bytes[0] }));
            }
        }