Exemplo n.º 1
0
        private void CreateIcmpSocket()
        {
            IPEndPoint srcEndPoint = new IPEndPoint(IPAddress.Any, 0);

            if (!string.Empty.Equals(sourceIPAddress.TextValue))
            {
                try
                {
                    srcEndPoint = new IPEndPoint(IPAddress.Parse(sourceIPAddress.TextValue), 0);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, this.Text);
                    return;
                }
            }
            else
            {
                sourceIPAddress.TextValue = "";
            }

            try
            {
                icmpSocket = new IcmpSocket(srcEndPoint);
                icmpSocket.MessageReceived += IcmpSocket_MessageReceived;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, this.Text);
                return;
            }

            sourceIPAddress.Enabled = false;
            IPEndPoint endPoint = icmpSocket.LocalEndPoint;

            sourceIPAddress.TextValue = endPoint.Address.ToString();
            bind.Enabled  = false;
            close.Enabled = true;
        }
Exemplo n.º 2
0
        private void CloseIcmpSocket()
        {
            if (icmpSocket == null)
            {
                return;
            }

            if (InvokeRequired)
            {
                Invoke((Action) delegate
                {
                    CloseIcmpSocket();
                });
                return;
            }
            icmpSocket.Close();
            icmpSocket              = null;
            bind.Enabled            = true;
            sendButton.Enabled      = false;
            close.Enabled           = false;
            sourceIPAddress.Enabled = true;
        }
Exemplo n.º 3
0
        private void CreateIcmpSocket()
        {
            IPEndPoint srcEndPoint = new IPEndPoint(IPAddress.Any, 0);

            if (!string.Empty.Equals(sourceIPAddress.Text))
            {
                try
                {
                    srcEndPoint = new IPEndPoint(IPAddress.Parse(sourceIPAddress.Text), 0);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, this.Text);
                    return;
                }
            }
            else
            {
                sourceIPAddress.Text = "";
            }

            try
            {
                icmpSocket = new IcmpSocket(srcEndPoint);
                icmpSocket.MessageReceived += icmpSocket_MessageReceived;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, this.Text);
                return;
            }

            sourceIPAddress.Enabled = false;
            IPEndPoint endPoint = icmpSocket.LocalEndPoint;
            sourceIPAddress.Text = endPoint.Address.ToString();
            bind.Enabled = false;
        }