Exemple #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            string mac = WOL2DNSHelper.GetMACAddress(txtName.Text);

            if (mac == null || mac.Length == 0)
            {
                mac = WOL2DNSHelper.GetMACAddress(txtIp.Text);
            }

            if (mac != null || mac.Length > 0)
            {
                txtMac.Text = mac;
            }
        }
Exemple #2
0
        /// <summary>
        /// This function scans a single host
        /// </summary>
        /// <param name="h">A WOL2Host containing the information
        /// required to scan a host.</param>
        /// <returns>True, if the host was successfully scanned.</returns>
        private bool ScanHost(WOL2Host h)
        {
            bool bRet = false;

            IPAddress ip = IPAddress.Parse(h.GetIpAddress());

            byte[]      buffer      = new byte[32];
            Ping        myPing      = new Ping();
            PingOptions pingOptions = new PingOptions();
            PingReply   reply       = myPing.Send(ip, m_iPingTimeout, buffer, pingOptions); // send the ping

            if (reply.Status == IPStatus.Success)
            {
                // Found a host
                // WOL2Host h = new WOL2Host();
                try
                {
                    h.SetIpAddress(ip.ToString());
                    h.SetMacAddress(WOL2DNSHelper.GetMACAddress(h.GetIpAddress()));
                    h.SetName(Dns.GetHostEntry(h.GetIpAddress()).HostName);

                    // ipv6 lookup
                    string lookup = h.GetName();
                    string ipv6   = WOL2DNSHelper.ResolveToIPv6Local(lookup);
                    if (ipv6 == null)
                    {
                        lookup = h.GetIpAddress();
                        ipv6   = WOL2DNSHelper.ResolveToIPv6Local(lookup);
                    }

                    if (ipv6 != null)
                    {
                        h.SetIpV6Address(ipv6);
                    }

                    // check if the hostname was found
                    bool bAdd = true;
                    if (m_bAddIfHostnameResolved)
                    {
                        bAdd = (h.GetIpAddress() != h.GetName());
                    }

                    if (m_bAddIfMacResolved)
                    {
                        bAdd = (h.GetMacAddress().Length != 0);
                    }

                    if (bAdd)
                    {
                        Monitor.Enter(Hosts);
                        Hosts.Add(h);
                        Monitor.Exit(Hosts);
                    }

                    MOE.Logger.DoLog("ScanHost(): Found host: " + h + ". " + (bAdd ? "Adding it." : "Not adding it."), MOE.Logger.LogLevel.lvlInfo);

                    bRet = bAdd;
                }
                catch (System.Net.Sockets.SocketException se)
                {
                    MOE.Logger.DoLog(se.ToString(), MOE.Logger.LogLevel.lvlWarning);
                }
                catch (Exception ex)
                {
                    MOE.Logger.DoLog(ex.ToString(), MOE.Logger.LogLevel.lvlWarning);
                }
            }

            MOE.Logger.DoLog("ScanHost(): finished job " + h.GetIpAddress(), MOE.Logger.LogLevel.lvlDebug);

            return(bRet);
        }