Ejemplo n.º 1
0
        private void btnLookUpIpV4_Click(object sender, EventArgs e)
        {
            string lookup = txtName.Text;

            if (lookup.Length > 0)
            {
                string[] ipv4 = WOL2DNSHelper.ResolveToIPv4(lookup);

                if (ipv4 == null || ipv4.Length == 0)
                {
                    string msg = MOE.Utility.GetStringFromRes("strHostnameInValid");
                    MessageBox.Show(this, msg, "Wake on lan tool 2", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    return;
                }

                contextMenuStrip1.Items.Clear();
                foreach (string s in ipv4)
                {
                    contextMenuStrip1.Items.Add(s);
                }

                contextMenuStrip1.Show(this.Left + btnLookUpIpV4.Left, this.Top + btnLookUpIpV4.Bottom);
            }
        }
Ejemplo n.º 2
0
        public List <String> getNetworks()
        {
            List <String> lst = new List <string>();

            foreach (UnicastIPAddressInformation uipi in m_ni.GetIPProperties().UnicastAddresses)
            {
                if (uipi.Address != null && uipi.Address.ToString() != "127.0.0.1")
                {
                    if (uipi.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        if (uipi.Address != null && uipi.IPv4Mask != null)
                        {
                            IPAddress ip = WOL2DNSHelper.GetNetworkAddress(uipi.Address, uipi.IPv4Mask);
                            IPAddress bc = WOL2DNSHelper.GetBroadcastAddress(uipi.Address, uipi.IPv4Mask);

                            lst.Add(ip.ToString() + " - " + bc.ToString() + " / " + uipi.IPv4Mask);
                        }
                        else
                        {
                            MOE.Logger.DoLog("Network " + uipi.ToString() + " is invalid!", MOE.Logger.LogLevel.lvlWarning);
                        }
                    }
                }
            }
            MOE.Logger.DoLog("WOL2NicFacade.getNetworks() for NIC " + m_ni.Name + " returns a list of " + lst.Count + " networks.", MOE.Logger.LogLevel.lvlDebug);
            return(lst);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Expands the given string using placeholder variables
        /// </summary>
        /// <param name="sFormat">The format string to expand.</param>
        /// <returns>The expanded string.</returns>
        public string ExpandVariables(string what)
        {
            String s = what;

            s = s.Replace("%name%", GetName());
            s = s.Replace("%ip%", GetIpAddress());
            s = s.Replace("%ipv6%", GetIpV6Address());
            s = s.Replace("%mac%", GetMacAddress());
            s = s.Replace("%comment%", GetDescription());
            s = s.Replace("%snmask%", GetSubnetMask());
            s = s.Replace("%groups%", GetGroups());
            s = s.Replace("%state%", StateAsString());
            s = s.Replace("%dname%", IsDynamicHost() ? GetName() : GetIpAddress());
            try
            {
                if (s.IndexOf("%dipv4%") >= 0)
                {
                    s = s.Replace("%dipv4%", WOL2DNSHelper.ResolveToIPv4(GetName())[0]);
                }
            }
            catch { }
            try
            {
                if (s.IndexOf("%dipv6%") >= 0)
                {
                    s = s.Replace("%dipv6%", WOL2DNSHelper.ResolveToIPv6Local(GetName()));
                }
            }
            catch { }
            return(s);
        }
Ejemplo n.º 4
0
        public void ScanIPv4Network(IPAddress Address, IPAddress IPv4Mask)
        {
            IPAddress ip = WOL2DNSHelper.GetNetworkAddress(Address, IPv4Mask);
            IPAddress bc = WOL2DNSHelper.GetBroadcastAddress(Address, IPv4Mask);

            MOE.Logger.DoLog("ScanIPv4Network: Scanning network " + ip + " with mask " + IPv4Mask, MOE.Logger.LogLevel.lvlInfo);

            // 'ip' is now the network address
            ScanIPv4Range(ip, bc, IPv4Mask);
        }
Ejemplo n.º 5
0
        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            txtIp.Text = e.ClickedItem.Text;

            // find the subnet mask
            string sn = WOL2DNSHelper.ResolveSubnetMask(IPAddress.Parse(txtIp.Text));

            if (sn != null)
            {
                txtSnMask.Text = sn;
            }
        }
Ejemplo n.º 6
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;
            }
        }
Ejemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            string lookup = txtName.Text;

            if (lookup.Length > 0)
            {
                string ipv6 = WOL2DNSHelper.ResolveToIPv6Local(lookup);
                if (ipv6 == null)
                {
                    lookup = txtIp.Text;
                    if (lookup.Length > 0)
                    {
                        ipv6 = WOL2DNSHelper.ResolveToIPv6Local(lookup);
                    }
                }

                if (ipv6 != null)
                {
                    txtIPv6.Text = ipv6;
                }
            }
        }
Ejemplo n.º 8
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);
        }