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; }
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; }
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; }