Пример #1
0
        public static void RefreshLoads()
        {
            foreach (var pcinfo in WOLClass.getNetworkComputers())
            {
                string[] pc = pcinfo.Split(',');
                if (NetworkInfo.ContainsKey(pc[0]) == false)            //2
                {
                    if (OfflineNetworkInfo.ContainsKey(pc[0]) == false) //2
                    {
                        //New Online PC

                        /*
                         * if (AllIP.Contains(pc[2]))
                         * {
                         *  continue;
                         * }
                         */
                        NetworkItems NI = new NetworkItems();
                        NI.HostName   = NI.ShownName = pc[0];//2
                        NI.IP         = pc[0];
                        NI.PCStatu    = PCStatus.Online;
                        NI.MacAddress = pc[1];
                        NetworkInfo.Add(NI.IP, NI);
                        ALLNetworks.Add(NI.IP, NI);
                    }
                    else
                    {
                        //Offline but now Online
                        NetworkItems NI = OfflineNetworkInfo[pc[0]];// pc[2]];
                        NI.IP      = pc[0];
                        NI.PCStatu = PCStatus.Online;
                        if (NI.MacAddress == "" || string.IsNullOrEmpty(NI.MacAddress))
                        {
                            NI.MacAddress = pc[1];
                        }
                        NetworkInfo.Add(NI.IP, NI);
                        OfflineNetworkInfo.Remove(NI.IP);
                    }
                }
                else
                {
                    if (OfflineNetworkInfo.ContainsKey(pc[0]))       //2
                    {                                                //Offline but now Online
                        NetworkItems NI = OfflineNetworkInfo[pc[0]]; //2
                        NI.IP      = pc[0];
                        NI.PCStatu = PCStatus.Online;
                        if (NI.MacAddress == "" || string.IsNullOrEmpty(NI.MacAddress))
                        {
                            NI.MacAddress = pc[1];
                        }
                        OfflineNetworkInfo.Remove(NI.IP);
                    }
                    else
                    {
                        //Online but now Offline
                    }
                }
            }
        }
Пример #2
0
        public static void Loed()
        {
            NetworkInfo        = new Dictionary <string, NetworkItems>();
            OfflineNetworkInfo = new Dictionary <string, NetworkItems>();
            ALLNetworks        = new Dictionary <string, NetworkItems>();
            WOLClass.SetMyIP();
            //  List<string> notinsure = new List<string>();
            var gnc = WOLClass.getNetworkComputers();

            foreach (var pcinfo in gnc)
            {
                string[] pc = pcinfo.Split(',');

                /*
                 * if (pc[2].StartsWith("192.168"))
                 * {
                 *  notinsure.Add(pcinfo);
                 *  continue;
                 * }
                 */
                NetworkItems NI = new NetworkItems();
                NI.HostName   = NI.ShownName = pc[0];//2
                NI.IP         = pc[0];
                NI.PCStatu    = PCStatus.Online;
                NI.MacAddress = pc[1];
                //AllIP.Add(NI.IP);
                NetworkInfo.Add(NI.IP, NI);
                ALLNetworks.Add(NI.IP, NI);
            }

            /*
             * foreach (var pcinfo in notinsure)
             * {
             *  string[] pc = pcinfo.Split(',');
             *  if (AllIP.Contains(pc[2]))
             *  {
             *      continue;
             *  }
             *  NetworkItems NI = new NetworkItems();
             *  NI.HostName = pc[2];
             *  NI.IP = pc[0];
             *  NI.PCStatu = PCStatus.Online;
             *  NI.MacAddress = pc[1];
             *  NetworkInfo.Add(NI.HostName, NI);
             *  ALLNetworks.Add(NI.HostName, NI);
             * }
             */
        }
Пример #3
0
        public bool WakeFunction(string MAC_ADDRESS)
        {
            try
            {
                MAC_ADDRESS = MAC_ADDRESS.Replace("-", "");
                WOLClass client = new WOLClass();
                client.Connect(new
                               IPAddress(0xffffffff), //255.255.255.255  i.e broadcast
                               0x2fff);               // port=12287 let's use this one
                client.SetClientToBrodcastMode();
                //set sending bites
                long counter = 0;
                //buffer to be send
                byte[] bytes = new byte[1024];   // more than enough :-)
                //first 6 bytes should be 0xFF
                for (int y = 0; y < 6; y++)
                {
                    bytes[counter++] = 0xFF;
                }
                //now repeate MAC 16 times
                for (int y = 0; y < 16; y++)
                {
                    int i = 0;
                    for (int z = 0; z < 6; z++)
                    {
                        bytes[counter++] =
                            byte.Parse(MAC_ADDRESS.Substring(i, 2),
                                       NumberStyles.HexNumber);
                        i += 2;
                    }
                }

                //now send wake up packet
                int reterned_value = client.Send(bytes, 1024);
                if (reterned_value <= 0)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch { return(false); }
        }