Beispiel #1
0
        private void send()
        {
            string strdata;

            strdata = this.textBox_editable.Text;

            if (strdata == "")
            {
                return;
            }
            if (this.checkBox_send_hexa_data.Checked)
            {
                byte[] b = easy_socket.hexa_convert.hexa_to_byte(strdata);
                if (b == null)
                {
                    MessageBox.Show(this, "Please enter hexa data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    clt.send(b);
                }
            }
            else
            {
                if (this.checkBox_crlf.Checked)
                {
                    strdata += "\r\n";
                }
                clt.send(strdata);
            }

            if (!this.textBox_telnet.Text.EndsWith("\r\n"))
            {
                this.textBox_telnet_add("\r\n");
            }
            this.textBox_telnet_add(strdata);
            this.textBox_editable.Text = "";
            if (!this.textBox_telnet.Text.EndsWith("\r\n"))
            {
                this.textBox_telnet_add("\r\n");
            }
        }
        public void wake_on_lan(string mac_addr, string ip, int port)
        {
            mac_addr = mac_addr.Replace("-", "");
            mac_addr = mac_addr.Replace(".", "");
            mac_addr = mac_addr.Replace(":", "");
            if (mac_addr.Length < 10)
            {
                System.Windows.Forms.MessageBox.Show("Error bad MAC address value", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }

            easy_socket.udp.Socket_Data s = new easy_socket.udp.Socket_Data(ip, port);
            s.event_Socket_Data_Error          += new easy_socket.udp.Socket_Data_Error_EventHandler(Socket_Data_Error_EventHandler);
            s.event_Socket_Data_Send_Completed += new easy_socket.udp.Socket_Data_Send_Completed_EventHandler(Socket_Data_Send_Completed_EventHandler);
            s.allow_broadcast = true;

/*
 * AMD Publication# 20213
 * If the IEEE address for a particular node on the network
 * was 11h 22h 33h 44h 55h 66h, then the LAN controller
 * would be scanning for the data sequence (assuming an
 * Ethernet Frame):
 * DESTINATION SOURCE MISC FF FF FF FF FF
 * FF 11 22 33 44 55 66 11 22 33 44 55 66 11 22 33 44
 * 55 66 11 22 33 44 55 66 11 22 33 44 55 66 11 22 33
 * 44 55 66 11 22 33 44 55 66 11 22 33 44 55 66 11 22
 * 33 44 55 66 11 22 33 44 55 66 11 22 33 44 55 66 11
 * 22 33 44 55 66 11 22 33 44 55 66 11 22 33 44 55 66
 * 11 22 33 44 55 66 11 22 33 44 55 66 MISC CRC
 */
            byte[] bytes = new byte[6 + 6 * 16];
            //first 6 bytes should be 0xff
            for (int cpt = 0; cpt < 6; cpt++)
            {
                bytes[cpt] = 0xff;
            }
            //now repeate MAC 16 times
            for (int cpt = 0; cpt < 16; cpt++)
            {
                for (int cpt2 = 0; cpt2 < 6; cpt2++)
                {
                    bytes[6 + cpt * 6 + cpt2] = byte.Parse(mac_addr.Substring(2 * cpt2, 2),//mac address is at least 10 length see if (mac_addr.Length<10)
                                                           System.Globalization.NumberStyles.HexNumber);
                }
            }
            s.send(bytes);
            // wait for multiple handles (error and send completed)
            System.Threading.WaitHandle[] waithandles = new System.Threading.WaitHandle[2];
            waithandles[0] = evt_success;
            waithandles[1] = evt_error;
            System.Threading.WaitHandle.WaitAny(waithandles, 10000, true);
        }