コード例 #1
0
 /// <summary>
 /// create new subnet
 /// </summary>
 /// <param name="networkAddress">network address for this subnet </param>
 /// <param name="broadcastAddress">broadcast address for this subnet </param>
 /// <param name="firstUsableIp">first usable ip for this subnet </param>
 /// <param name="lastUsableIp">last usable ip for this subnet </param>
 public Subnet(string networkAddress, string broadcastAddress)
 {
     BroadcastAddress = broadcastAddress;
     NetworkAddress   = networkAddress;
     firstUsableIp    = IpAnalyzer.GetNextIp(NetworkAddress);
     lastUsableIp     = IpAnalyzer.GetPreviousIp(broadcastAddress);
 }
コード例 #2
0
        /// <summary>
        /// Get list of all usable ip addresses for this subnet
        /// </summary>
        /// <returns>List of usable ip's </returns>
        public List <string> GetUsableHosts()
        {
            List <string> result = new List <string>();
            string        next   = IpAnalyzer.GetNextIp(GetFirstUsableIp());

            while (next != GetLastUsableIp())
            {
                result.Add(next);
                next = IpAnalyzer.GetNextIp(next);
            }
            return(result);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            IpAnalyzer ip = new IpAnalyzer("213.6.2.253", 30);

            Console.WriteLine("Networkaddress : " + ip.GetNetworkAddress());
            Console.WriteLine("Broadcast address : " + ip.GetBroadcastAddress());
            Console.WriteLine("Total number of hosts : " + ip.GetNumberOfHosts());
            Console.WriteLine("number of usable hosts : " + ip.GetNumberOfValidHosts());
            Console.WriteLine("number of usable hosts : " + ip.GetNumberOfValidHosts());
            Console.WriteLine(ip.ToString());
            Console.WriteLine("Wildcard mask : " + ip.GetWildcardMask());
            Console.WriteLine("Binary ip address : " + ip.GetBinaryNotaion());
            Console.WriteLine("Class : " + ip.GetClass());
            Console.WriteLine("CIDR notation : " + ip.GetCIDRNotation());
            Console.WriteLine("Is public : " + (ip.IsPublic()));
            Console.WriteLine("Is private : " + (ip.IsPrivate()));
            Console.WriteLine("Short : " + ip.GetShort());
            Console.WriteLine("Hex : " + (ip.ip));
            Console.WriteLine("\n\n\n\n\n");
            foreach (var subnet in ip.GetSubnets())
            {
                Console.WriteLine(subnet.NetworkAddress + "           " + subnet.GetFirstUsableIp() + " -- " + subnet.GetLastUsableIp() + "    " + subnet.BroadcastAddress);
            }
        }