private static void PrintTcp6Statistics() { TcpStatistics stats = IPGlobalProperties.GetIPGlobalProperties().GetTcpIPv6Statistics(); Console.WriteLine("--TCPv6 Statistics--"); PrintProperties(stats); }
/// <summary> /// Set the TCP statistics fields /// </summary> private void DumpStats() { IPGlobalProperties stats = IPGlobalProperties.GetIPGlobalProperties(); TcpStatistics tcpstat = stats.GetTcpIPv4Statistics(); UdpStatistics udpstat = stats.GetUdpIPv4Statistics(); // set labels // this doesn't need to be done each time setLabels(); // set the TCP field labels connAcceptField.Text = tcpstat.ConnectionsAccepted.ToString(); connInitiatedField.Text = tcpstat.ConnectionsInitiated.ToString(); cumulativeConnectionsField.Text = tcpstat.CumulativeConnections.ToString(); errorsReceivedField.Text = tcpstat.ErrorsReceived.ToString(); failedConAttField.Text = tcpstat.FailedConnectionAttempts.ToString(); maxConnField.Text = tcpstat.MaximumConnections.ToString(); resetConnField.Text = tcpstat.ResetConnections.ToString(); resetsSentField.Text = tcpstat.ResetsSent.ToString(); segsReceivedField.Text = tcpstat.SegmentsReceived.ToString(); segsResentField.Text = tcpstat.SegmentsResent.ToString(); segsSentField.Text = tcpstat.SegmentsSent.ToString(); // set the UDP field labels dataReceivedField.Text = udpstat.DatagramsReceived.ToString(); dataSentField.Text = udpstat.DatagramsSent.ToString(); incDataDiscField.Text = udpstat.IncomingDatagramsDiscarded.ToString(); incDataErrField.Text = udpstat.IncomingDatagramsWithErrors.ToString(); }
static void Main(string[] args) { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); Console.WriteLine("Domain Name : " + properties.DomainName); Console.WriteLine("Host Name : " + properties.HostName); //Get Active TCP Connections TcpConnectionInformation[] connections = properties.GetActiveTcpConnections(); //Get Active TCP Listener IPEndPoint[] endPointsTCP = properties.GetActiveTcpListeners(); //Get Active UDP Listener IPEndPoint[] endPointsUDP = properties.GetActiveUdpListeners(); //Get IP statistics information IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); //Get TCP statistical information TcpStatistics tcpstat = properties.GetTcpIPv4Statistics(); //Get UDP statistical information UdpStatistics udpStat = properties.GetUdpIPv4Statistics(); }
static DynamicJsonValue ToDynamic(TcpStatistics stats) { if (stats == null) { return(null); } var result = new DynamicJsonValue(); result[nameof(stats.ConnectionsAccepted)] = stats.GetConnectionsAcceptedSafely(); result[nameof(stats.ConnectionsInitiated)] = stats.GetConnectionsInitiatedSafely(); result[nameof(stats.CumulativeConnections)] = stats.GetCumulativeConnectionsSafely(); result[nameof(stats.CurrentConnections)] = stats.GetCurrentConnectionsSafely(); result[nameof(stats.ErrorsReceived)] = stats.GetErrorsReceivedSafely(); result[nameof(stats.FailedConnectionAttempts)] = stats.GetFailedConnectionAttemptsSafely(); result[nameof(stats.MaximumConnections)] = stats.GetMaximumConnectionsSafely(); result[nameof(stats.MaximumTransmissionTimeout)] = stats.GetMaximumTransmissionTimeoutSafely(); result[nameof(stats.MinimumTransmissionTimeout)] = stats.GetMinimumTransmissionTimeoutSafely(); result[nameof(stats.ResetConnections)] = stats.GetResetConnectionsSafely(); result[nameof(stats.ResetsSent)] = stats.GetResetsSentSafely(); result[nameof(stats.SegmentsReceived)] = stats.GetSegmentsReceivedSafely(); result[nameof(stats.SegmentsResent)] = stats.GetSegmentsResentSafely(); result[nameof(stats.SegmentsSent)] = stats.GetSegmentsSentSafely(); return(result); }
// Display the data for given TcpStatistics object. private static void DisplayTcpStatistics(TcpStatistics tcpStat) { Console.WriteLine( equalsFormatString, "Active Opens", tcpStat.ConnectionsInitiated); Console.WriteLine( equalsFormatString, "Passive Opens", tcpStat.ConnectionsAccepted); Console.WriteLine( equalsFormatString, "Failed Connection Attempts", tcpStat.FailedConnectionAttempts); Console.WriteLine( equalsFormatString, "Reset Connections", tcpStat.ResetConnections); Console.WriteLine( equalsFormatString, "Current Connections", tcpStat.CurrentConnections); Console.WriteLine( equalsFormatString, "Segments Received", tcpStat.SegmentsReceived); Console.WriteLine( equalsFormatString, "Segments Sent", tcpStat.SegmentsSent); Console.WriteLine( equalsFormatString, "Segments Retransmitted", tcpStat.SegmentsResent); }
public string GetSent() { //Sets the amount of data sent to variable "sent" tcpstat = ipgp.GetTcpIPv4Statistics(); long sent = tcpstat.SegmentsSent; //Returns amount of data sent formatted by method FormatBytes(long amt); return(FormatBytes(sent)); }
//</Snippet1> //<Snippet2> public static void ShowTcpStatistics(NetworkInterfaceComponent version) { //<Snippet21> IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpStatistics tcpstat = null; Console.WriteLine(""); switch (version) { case NetworkInterfaceComponent.IPv4: tcpstat = properties.GetTcpIPv4Statistics(); Console.WriteLine("TCP/IPv4 Statistics:"); break; case NetworkInterfaceComponent.IPv6: tcpstat = properties.GetTcpIPv6Statistics(); Console.WriteLine("TCP/IPv6 Statistics:"); break; default: throw new ArgumentException("version"); // break; } //</Snippet21> Console.WriteLine(" Minimum Transmission Timeout............. : {0}", tcpstat.MinimumTransmissionTimeout); Console.WriteLine(" Maximum Transmission Timeout............. : {0}", tcpstat.MaximumTransmissionTimeout); Console.WriteLine(" Connection Data:"); Console.WriteLine(" Current ............................ : {0}", tcpstat.CurrentConnections); Console.WriteLine(" Cumulative .......................... : {0}", tcpstat.CumulativeConnections); Console.WriteLine(" Initiated ........................... : {0}", tcpstat.ConnectionsInitiated); Console.WriteLine(" Accepted ............................ : {0}", tcpstat.ConnectionsAccepted); Console.WriteLine(" Failed Attempts ..................... : {0}", tcpstat.FailedConnectionAttempts); Console.WriteLine(" Reset ............................... : {0}", tcpstat.ResetConnections); Console.WriteLine(""); Console.WriteLine(" Segment Data:"); Console.WriteLine(" Received ........................... : {0}", tcpstat.SegmentsReceived); Console.WriteLine(" Sent ................................ : {0}", tcpstat.SegmentsSent); Console.WriteLine(" Retransmitted ....................... : {0}", tcpstat.SegmentsResent); Console.WriteLine(""); }
public string GetReceived() { //Sets the amount of segments received to variable "rec" tcpstat = ipgp.GetTcpIPv4Statistics(); long rec = tcpstat.SegmentsReceived; RECV_TOTAL = rec; //Returns value "rec" in a string formatted to KB, MB, or GB depending on the amount. return(FormatBytes(rec)); }
public TCPNetworkStatistics() { IPGlobalProperties IPproperties = IPGlobalProperties.GetIPGlobalProperties(); TcpStatistics tcpNetworkStats = IPproperties.GetTcpIPv4Statistics(); this.CurrentConnections = tcpNetworkStats.CurrentConnections; this.CumulativeConections = tcpNetworkStats.CumulativeConnections; this.InitiatedConnections = tcpNetworkStats.ConnectionsInitiated; this.AcceptedConnections = tcpNetworkStats.ConnectionsAccepted; this.FailedConnectionAttempts = tcpNetworkStats.FailedConnectionAttempts; this.ConnectionsReset = tcpNetworkStats.ResetConnections; }
public static void DisplayTcpStatistics(NetworkInterfaceComponent version, TextWriter outputStream) { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpStatistics tcpstat = null; outputStream.WriteLine(""); switch (version) { case NetworkInterfaceComponent.IPv4: tcpstat = properties.GetTcpIPv4Statistics(); outputStream.WriteLine("TCP/IPv4 Statistics:"); break; case NetworkInterfaceComponent.IPv6: tcpstat = properties.GetTcpIPv6Statistics(); outputStream.WriteLine("TCP/IPv6 Statistics:"); break; default: throw new ArgumentException("version"); } outputStream.WriteLine(" Minimum Transmission Timeout. : {0}", tcpstat.MinimumTransmissionTimeout); outputStream.WriteLine(" Maximum Transmission Timeout : {0}", tcpstat.MaximumTransmissionTimeout); outputStream.WriteLine(" Connection Data:"); outputStream.WriteLine(" Current : {0}", tcpstat.CurrentConnections); outputStream.WriteLine(" Cumulative : {0}", tcpstat.CumulativeConnections); outputStream.WriteLine(" Initiated : {0}", tcpstat.ConnectionsInitiated); outputStream.WriteLine(" Accepted : {0}", tcpstat.ConnectionsAccepted); outputStream.WriteLine(" Failed Attempts : {0}", tcpstat.FailedConnectionAttempts); outputStream.WriteLine(" Reset : {0}", tcpstat.ResetConnections); outputStream.WriteLine(""); outputStream.WriteLine(" Segment Data:"); outputStream.WriteLine(" Received ................... : {0}", tcpstat.SegmentsReceived); outputStream.WriteLine(" Sent : {0}", tcpstat.SegmentsSent); outputStream.WriteLine(" Retransmitted : {0}", tcpstat.SegmentsResent); outputStream.WriteLine(""); }
//</Snippet4> //<Snippet5> public static void ShowTcpTimeouts() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpStatistics tcpstat = properties.GetTcpIPv4Statistics(); Console.WriteLine(" Minimum Transmission Timeout............. : {0}", tcpstat.MinimumTransmissionTimeout); Console.WriteLine(" Maximum Transmission Timeout............. : {0}", tcpstat.MaximumTransmissionTimeout); Console.WriteLine(" Maximum connections ............. : {0}", tcpstat.MaximumConnections); Console.WriteLine(); }
public static long?GetErrorsReceivedSafely(this TcpStatistics statistics) { try { if (statistics == null) { return(null); } return(statistics.ErrorsReceived); } catch (PlatformNotSupportedException) { return(null); } }
public static long?GetFailedConnectionAttemptsSafely(this TcpStatistics statistics) { try { if (statistics == null) { return(null); } return(statistics.FailedConnectionAttempts); } catch (PlatformNotSupportedException) { return(null); } }
public static long?GetMaximumConnectionsSafely(this TcpStatistics statistics) { try { if (statistics == null) { return(null); } return(statistics.MaximumConnections); } catch (PlatformNotSupportedException) { return(null); } }
//</Snippet6> //<Snippet7> public static void ShowTcpSegmentData() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpStatistics tcpstat = properties.GetTcpIPv4Statistics(); Console.WriteLine(" Segment Data:"); Console.WriteLine(" Received ........................... : {0}", tcpstat.SegmentsReceived); Console.WriteLine(" Sent ................................ : {0}", tcpstat.SegmentsSent); Console.WriteLine(" Retransmitted ....................... : {0}", tcpstat.SegmentsResent); Console.WriteLine(" Resent with reset ................... : {0}", tcpstat.ResetsSent); Console.WriteLine(); }
public static long?GetMinimumTransmissionTimeoutSafely(this TcpStatistics statistics) { try { if (statistics == null) { return(null); } return(statistics.MinimumTransmissionTimeout); } catch (PlatformNotSupportedException) { return(null); } }
public static Task <TcpStatistics> GetTcpV4StatisticsAsync(bool isIPv6 = false) { var properties = IPGlobalProperties.GetIPGlobalProperties(); TcpStatistics tcpStats = null; if (isIPv6) { tcpStats = properties.GetTcpIPv4Statistics(); } else { tcpStats = properties.GetTcpIPv4Statistics(); } return(Task.FromResult(tcpStats)); }
public static long?GetSegmentsSentSafely(this TcpStatistics statistics) { try { if (statistics == null) { return(null); } return(statistics.SegmentsSent); } catch (PlatformNotSupportedException) { return(null); } }
public static long?GetConnectionsInitiatedSafely(this TcpStatistics statistics) { try { if (statistics == null) { return(null); } return(statistics.ConnectionsInitiated); } catch (PlatformNotSupportedException) { return(null); } }
//</Snippet5> //<Snippet6> public static void ShowTcpConnectionStatistics() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpStatistics tcpstat = properties.GetTcpIPv4Statistics(); Console.WriteLine(" Connection Data:"); Console.WriteLine(" Current ............................ : {0}", tcpstat.CurrentConnections); Console.WriteLine(" Cumulative .......................... : {0}", tcpstat.CumulativeConnections); Console.WriteLine(" Initiated ........................... : {0}", tcpstat.ConnectionsInitiated); Console.WriteLine(" Accepted ............................ : {0}", tcpstat.ConnectionsAccepted); Console.WriteLine(" Failed Attempts ..................... : {0}", tcpstat.FailedConnectionAttempts); Console.WriteLine(" Reset ............................... : {0}", tcpstat.ResetConnections); Console.WriteLine(" Errors .............................. : {0}", tcpstat.ErrorsReceived); Console.WriteLine(); }
private void tCPIPv6StatisticsToolStripMenuItem_Click(object sender, EventArgs e) { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpStatistics tcpStat = properties.GetTcpIPv6Statistics(); StatTextBox.Text = "Статисктика TCP для IPv6:" + "\r\r"; StatTextBox.Text += "Общее число установленных подключений: " + tcpStat.CumulativeConnections + "\r"; StatTextBox.Text += "Число текущих подключений: " + tcpStat.CurrentConnections + "\r"; StatTextBox.Text += "Сбоев при подключении: " + tcpStat.FailedConnectionAttempts + "\r"; StatTextBox.Text += "Сброшено подключений: " + tcpStat.ResetConnections + "\r"; StatTextBox.Text += "Запросов на подключение: " + tcpStat.ConnectionsAccepted + "\r"; StatTextBox.Text += "Число полученных ошибок: " + tcpStat.ErrorsReceived + "\r\r"; StatTextBox.Text += "Максимальное число поддерживаемых подключений: " + tcpStat.MaximumConnections + "\r"; StatTextBox.Text += "Минимальное время ожидания при отправке сегмента: " + tcpStat.MinimumTransmissionTimeout + "\r"; StatTextBox.Text += "Максимальное время ожидания при отправке сегмента: " + tcpStat.MaximumTransmissionTimeout + "\r\r"; StatTextBox.Text += "Отправлено сегментов: " + tcpStat.SegmentsSent + "\r"; StatTextBox.Text += "Получено сегментов: " + tcpStat.SegmentsReceived + "\r"; StatTextBox.Text += "Повторно отправленных сегментов: " + tcpStat.SegmentsResent; }
public NetStats() { //Sets up the base for Send/Receive data calculations. tcpstat = ipgp.GetTcpIPv4Statistics(); RECV_TOTAL = tcpstat.SegmentsReceived; SEND_TOTAL = tcpstat.SegmentsSent; //Configures the DataTable "cons" to hold four data columns. cons.Columns.Add("Process"); cons.Columns.Add("ID"); cons.Columns.Add("Local Port"); cons.Columns.Add("Remote Address"); cons.Columns.Add("Status"); //Configuring DataTable "recv" to represent received data recv.Columns.Add("Time", Type.GetType("System.Int32")); recv.Columns.Add("Speed", Type.GetType("System.Int32")); recv.Rows.Add(0, 0); //Configuring DataTable "send" to represent received data send.Columns.Add("Time", Type.GetType("System.Int32")); send.Columns.Add("Speed", Type.GetType("System.Int32")); send.Rows.Add(0, 0); }
public void PopulateTable() { //# UPDATES CONNECTION TABLE # //Renews TCP connection information. Clears DataTable "cons," ready for a new set of data. tcpi = ipgp.GetActiveTcpConnections(); tcpstat = ipgp.GetTcpIPv4Statistics(); cons.Rows.Clear(); //Creates a Row in the DataTable "cons" displaying the connections remote properties / status. foreach (TcpConnectionInformation t in tcpi) { try { //Fetches process according to ports Process pro = ipsh.GetProcessByPort(t.LocalEndPoint.Port); cons.Rows.Add(new Object[] { pro.ProcessName, pro.Id, t.LocalEndPoint.Port, t.RemoteEndPoint.Address, t.State }); } catch (Exception) { } } //# END CONNECTION TABLE # //# START RECV TABLE UPDATE # DataTable tmp = new DataTable(); tmp.Columns.Add("Time", Type.GetType("System.Int32")); tmp.Columns.Add("Speed", Type.GetType("System.Int32")); tmp.Rows.Add(0, (tcpstat.SegmentsReceived - RECV_TOTAL)); for (int a = 0; a < 59; a++) { try { DataRow dr = recv.Rows[a]; int time = Convert.ToInt32(dr.ItemArray[0].ToString()); tmp.Rows.Add(new Object[] { time++, recv.Rows[a].ItemArray[1] }); } catch (Exception) { break; } } RECV_TOTAL = tcpstat.SegmentsReceived; recv = tmp; //# END RECV TABLE UPDATE # //# START SEND TABLE UPDATE # DataTable snd = new DataTable(); snd.Columns.Add("Time", Type.GetType("System.Int32")); snd.Columns.Add("Speed", Type.GetType("System.Int32")); snd.Rows.Add(0, (tcpstat.SegmentsSent - SEND_TOTAL)); for (int a = 0; a < 59; a++) { try { DataRow dr = send.Rows[a]; int time = Convert.ToInt32(dr.ItemArray[0].ToString()); snd.Rows.Add(new Object[] { time++, send.Rows[a].ItemArray[1] }); } catch (Exception) { break; } } SEND_TOTAL = tcpstat.SegmentsSent; send = snd; }
private string GetTcpStatistics( NetworkInterfaceComponent version, IPGlobalProperties properties) { TcpStatistics tcpStat = null; StringBuilder tcpStatBuilder = new StringBuilder(); try { switch (version) { case NetworkInterfaceComponent.IPv4: tcpStat = properties.GetTcpIPv4Statistics(); tcpStatBuilder.Append("TCP/IPv4 Statistics\n"); break; case NetworkInterfaceComponent.IPv6: tcpStat = properties.GetTcpIPv6Statistics(); tcpStatBuilder.Append("TCP/IPv6 Statistics\n"); break; default: throw new ArgumentException("No such IP version"); } } catch (NetworkInformationException) { return(String.Empty); } tcpStatBuilder.Append("=================================================\n"); tcpStatBuilder.AppendFormat(" Minimum Transmission Timeout .. : {0}\n", tcpStat.MinimumTransmissionTimeout); tcpStatBuilder.AppendFormat(" Maximum Transmission Timeout .. : {0}\n", tcpStat.MaximumTransmissionTimeout); tcpStatBuilder.AppendFormat(" Maximum Connections ........... : {0}\n", tcpStat.MaximumConnections); tcpStatBuilder.AppendFormat(" Connection Data:\n"); tcpStatBuilder.AppendFormat(" Current ...................... : {0}\n", tcpStat.CurrentConnections); tcpStatBuilder.AppendFormat(" Cumulative ................... : {0}\n", tcpStat.CumulativeConnections); tcpStatBuilder.AppendFormat(" Initiated .................... : {0}\n", tcpStat.ConnectionsInitiated); tcpStatBuilder.AppendFormat(" Accepted ..................... : {0}\n", tcpStat.ConnectionsAccepted); tcpStatBuilder.AppendFormat(" Failed Attempts .............. : {0}\n", tcpStat.FailedConnectionAttempts); tcpStatBuilder.AppendFormat(" Reset ........................ : {0}\n", tcpStat.ResetConnections); tcpStatBuilder.AppendFormat(" Errors ....................... : {0}\n", tcpStat.ErrorsReceived); tcpStatBuilder.AppendFormat(" Segment Data:\n"); tcpStatBuilder.AppendFormat(" Received ..................... : {0}\n", tcpStat.SegmentsReceived); tcpStatBuilder.AppendFormat(" Sent ......................... : {0}\n", tcpStat.SegmentsSent); tcpStatBuilder.AppendFormat(" Retransmitted ................ : {0}\n", tcpStat.SegmentsResent); tcpStatBuilder.AppendFormat(" Resent with reset ............ : {0}\n", tcpStat.ResetsSent); TcpConnectionInformation[] connectionsInfo = properties.GetActiveTcpConnections(); tcpStatBuilder.AppendFormat(" Active Connections ............ : {0}\n", connectionsInfo.Length); if (connectionsInfo.Length > 0) { tcpStatBuilder.Append(" Local Address Port Remote Address Port\n"); } foreach (TcpConnectionInformation connectionInfo in connectionsInfo) { tcpStatBuilder.AppendFormat(" {0, -15}:{1} {2, -15}:{3}\n", connectionInfo.LocalEndPoint.Address, connectionInfo.LocalEndPoint.Port, connectionInfo.RemoteEndPoint.Address, connectionInfo.RemoteEndPoint.Port); } IPEndPoint[] endPoints = properties.GetActiveTcpListeners(); tcpStatBuilder.AppendFormat(" TCP Listeners ................. : {0}\n", endPoints.Length); if (endPoints.Length > 0) { tcpStatBuilder.Append(" Local Address Port\n"); } foreach (IPEndPoint endPoint in endPoints) { tcpStatBuilder.AppendFormat(" {0, -15}:{1}\n", endPoint.Address, endPoint.Port); } return(tcpStatBuilder.ToString()); }