Пример #1
0
        private void AsyncRetrieveMac(object parameter)
        {
            var iEntry        = (KeyValuePair <IPAddress, string>)parameter;
            var iEntryAddress = iEntry.Key;
            var iEntryTitle   = iEntry.Value;

            if (iEntryAddress.AddressFamily == AddressFamily.InterNetwork)
            {
                byte[] macBytes       = new byte[6];
                int    macBytesLength = macBytes.Length;

                int ipDestinationBytes = BitConverter.ToInt32(iEntryAddress.GetAddressBytes(), 0);
                int res = NativeMethods.SendARP(ipDestinationBytes, 0, macBytes, ref macBytesLength);

                if ((res == 0) && ((macBytes[0] != 0) || (macBytes[1] != 0) || (macBytes[2] != 0) || (macBytes[3] != 0) || (macBytes[4] != 0) || (macBytes[5] != 0)))
                {
                    worker.ReportProgress(-1, new ImportProgressState("Last found: " + iEntryAddress.ToString()));
                    if (string.IsNullOrEmpty(iEntryTitle))
                    {
                        try {
                            var hostEntry = System.Net.Dns.GetHostEntry(iEntryAddress);
                            var hostName  = hostEntry.HostName.Split(new char[] { '.' }, 2)[0];
                            if (string.IsNullOrEmpty(hostName))
                            {
                                iEntryTitle = iEntryAddress.ToString();
                            }
                            else
                            {
                                iEntryTitle = hostName + " at " + iEntryAddress.ToString();
                                worker.ReportProgress(-1, new ImportProgressState("Last found: " + hostName + " at " + iEntryAddress.ToString()));
                            }
                        } catch (SocketException) { //NoSuchHostIsKnown
                            iEntryTitle = iEntryAddress.ToString();
                        }
                    }

                    var macText  = (macBytes[0].ToString("x2") + ":" + macBytes[1].ToString("x2") + ":" + macBytes[2].ToString("x2") + ":" + macBytes[3].ToString("x2") + ":" + macBytes[4].ToString("x2") + ":" + macBytes[5].ToString("x2")).ToUpper();
                    var iAddress = new MagiWolDocument.Address(iEntryTitle, macText, "", "", null, null, false, false);

                    lock (_syncRootAsyncMac) {
                        if (!this._asyncMacsList.Contains(iAddress))
                        {
                            this._asyncMacsList.Add(iAddress);
                        }
                    }
                }
            }

            Interlocked.Increment(ref this._asyncMacTotalCounter);
        }
Пример #2
0
 private void mnuChange_Click(object sender, EventArgs e)
 {
     if (list.SelectedItems.Count == 1)
     {
         MagiWolDocument.Address currDestination = (MagiWolDocument.Address)list.SelectedItems[0];
         using (var frm = new DetailForm(currDestination)) {
             if (frm.ShowDialog(this) == DialogResult.OK)
             {
                 currDestination = frm.Destination;
                 UpdateData(new MagiWolDocument.Address[] { currDestination });
             }
         }
     }
 }
Пример #3
0
        public DetailForm(MagiWolDocument.Address destination)
        {
            InitializeComponent();
            this.Font = SystemFonts.MessageBoxFont;
            var fixedSizeFont = new Font("Courier New", base.Font.Size, base.Font.Style);

            this.textMac.Font      = fixedSizeFont;
            this.textSecureOn.Font = fixedSizeFont;

            this.Destination = destination;

            //foreach (Control iControl in this.Controls) {
            foreach (Control iControl in new Control[] { textTitle, textMac, textSecureOn, checkBroadcastAddress, checkBroadcastPort })   //because of Mono
            {
                erp.SetIconPadding(iControl, 4);
                erp.SetIconAlignment(iControl, ErrorIconAlignment.MiddleLeft);
            }
        }
Пример #4
0
 public QuickWakeForm(MagiWolDocument.Address address)
     : this()
 {
     if (address != null)
     {
         textMac.Text      = address.Mac;
         textSecureOn.Text = address.SecureOn;
         if (address.IsBroadcastHostValid)
         {
             checkBroadcastAddress.Checked = true;
             textBroadcastAddress.Text     = address.BroadcastHost;
         }
         if (address.IsBroadcastPortValid)
         {
             checkBroadcastPort.Checked = true;
             textBroadcastPort.Text     = address.BroadcastPort.ToString(CultureInfo.CurrentCulture);
         }
     }
 }
Пример #5
0
        public static void SendMagicPacket(MagiWolDocument.Address address)
        {
            var broadcastPort = Settings.BroadcastPort;

            if (address.IsBroadcastPortValid)
            {
                broadcastPort = address.BroadcastPort;
            }

            if (Settings.UseIPv4)
            {
                var broadcastHost = Settings.BroadcastHost;
                if (address.IsBroadcastHostValid)
                {
                    broadcastHost = address.BroadcastHost;
                }

                SendMagicPacket(address.Mac, address.SecureOn, broadcastHost, broadcastPort);
            }
            if (Settings.UseIPv6)
            {
                Medo.Net.WakeOnLan.SendMagicPacketIPv6(address.Mac, address.SecureOn, IPAddress.IPv6Any, broadcastPort);
            }
        }
Пример #6
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (this.Destination == null)
            {
                this.Destination = new MagiWolDocument.Address();
            }

            this.Destination.Title    = textTitle.Text;
            this.Destination.Mac      = textMac.Text;
            this.Destination.SecureOn = textSecureOn.Text;

            string host;

            if (checkBroadcastAddress.Checked)
            {
                if (string.IsNullOrEmpty(textBroadcastAddress.Text.Trim()) == false)
                {
                    host = textBroadcastAddress.Text.Trim();
                    this.Destination.IsBroadcastHostValid = true;
                }
                else
                {
                    host = Settings.BroadcastHost;
                    this.Destination.IsBroadcastHostValid = false;
                }
            }
            else
            {
                host = this.Destination.BroadcastHost;
                this.Destination.IsBroadcastHostValid = false;
            }

            int port;

            if (checkBroadcastPort.Checked)
            {
                if (int.TryParse(textBroadcastPort.Text, NumberStyles.Integer, CultureInfo.InvariantCulture, out port))
                {
                    if ((port >= 0) || (port <= 65535))
                    {
                        this.Destination.IsBroadcastPortValid = true;
                    }
                    else
                    {
                        port = Settings.BroadcastPort;
                        this.Destination.IsBroadcastPortValid = false;
                    }
                }
                else
                {
                    port = Settings.BroadcastPort;
                    this.Destination.IsBroadcastPortValid = false;
                }
            }
            else
            {
                port = this.Destination.BroadcastPort;
                this.Destination.IsBroadcastPortValid = false;
            }

            this.Destination.BroadcastHost = host;
            this.Destination.BroadcastPort = port;

            this.Destination.Notes = textNotes.Text;
        }