Ejemplo n.º 1
0
 // vrátí všechny možné adresy pomocí netmask a broadcastu
 public IPAddress[] PosibleAddresses()
 {
     if (PosibleAddresesList != null)
     {
         return(PosibleAddresesList.ToArray());
     }
     PosibleAddresesList = new List <IPAddress>();
     byte[] broadcast = BroadCast.GetAddressBytes();
     byte[] network   = NetworkAddr.GetAddressBytes();
     for (int oct1 = network[0]; oct1 <= broadcast[0]; oct1++)
     {
         for (int oct2 = network[1]; oct2 <= broadcast[1]; oct2++)
         {
             for (int oct3 = network[2]; oct3 <= broadcast[2]; oct3++)
             {
                 for (int oct4 = network[3]; oct4 <= broadcast[3]; oct4++)
                 {
                     PosibleAddresesList.Add(new IPAddress(new byte[] { (byte)oct1, (byte)oct2, (byte)oct3, (byte)oct4 }));
                 }
             }
         }
     }
     PosibleAddresesList.RemoveAt(0);
     PosibleAddresesList.RemoveAt(PosibleAddresesList.Count - 1);
     return(PosibleAddresses());
 }
Ejemplo n.º 2
0
        // zjistí jestli je addrese ve stejné síti
        public bool InNetwork(IPAddress addr)
        {
#if DEBUG
            //Console.WriteLine(addr);
            //Console.WriteLine(NetworkAddr.ToString());
            //Console.WriteLine(GetNetwork(addr).ToString());
            //Console.WriteLine("---------------------------------------------");
#endif
            return(NetworkAddr.ToString() == GetNetwork(addr).ToString());
        }