Click here to Skip to main content
11,417,390 members (53,440 online)
Click here to Skip to main content

Netstat Example

, 16 Feb 2003
Rate this:
Please Sign up or sign in to vote.
Sample classes to gather network statics for several protocols.

Netstat screenshot

Introduction

I have seen alot of requests on how to implement network statistics in .NET applications lately, however, I have not been able to find any .NET classes that do this.

I decided to write a simple VB.NET example on how to implement this with the help of the IP Helper API's. I am fairly new to .NET so the code approach might not be 100% 'politically correct' at all times, but I have tried to keep this as much .NET as I could. If you see something awful, please disregard it.

Using the Code

The NetStat class is the parent class because the class has several sub-classes: IP, UDP, TCP and ICMP. These classes contain properties which hold network statistics. You have to update these properties with the Class.Update method.

This method takes an optional parameter in the IP and TCP classes. If set to True this will update information which is not likely to change. The default is False. Also, if anything went wrong in the Update method, the return value is 0, so it's non-zero on success (It returns the size of structure). You get the error message by retrieving the .LastError property.

I have included a sample project with it, so you will get the picture pretty fast.

It can look something like this;

Dim clsUDP As New NetStat.IP

If clsUDP.Update() <> 0 Then
    ' Success, get properties
    MsgBox("Datagrams received: " & clsUDP.InDatagrams.ToString)
Else
    ' Error, Call LastError
    Msgbox "An error occured; " & clsUDP.LastError
End If

If you find a bug or if you think there is something wrong with the code please mail me about it! Finally; Tips, comments and/or suggestions would be deeply appreciated! Thank you.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Thomas_fn

Sweden Sweden
No Biography provided

Comments and Discussions

 
QuestionWat about COM Ports Pin
Bilal Haider28-Aug-08 7:02
memberBilal Haider28-Aug-08 7:02 
QuestionTCP Table and SetTcpEntry ??? Pin
Vitoto7-May-05 19:37
memberVitoto7-May-05 19:37 
QuestionWhere's the article? Pin
Paul Evans2-Feb-04 6:21
memberPaul Evans2-Feb-04 6:21 
AnswerRe: Where's the article? Pin
fanell2-Feb-04 11:01
memberfanell2-Feb-04 11:01 
GeneralGood Job! Pin
Jan-Peter3-Mar-03 10:16
memberJan-Peter3-Mar-03 10:16 
GeneralRe: Good Job! Pin
fanell4-Mar-03 12:33
memberfanell4-Mar-03 12:33 
QuestionLink to ZIP File broken? Pin
RabidKangaroo24-Feb-03 6:26
memberRabidKangaroo24-Feb-03 6:26 
AnswerRe: Link to ZIP File broken? Pin
Yanan Wang26-Feb-03 5:42
memberYanan Wang26-Feb-03 5:42 
GeneralRe: Link to ZIP File broken? Pin
bbooth@panamericanlife.com16-May-03 11:00
memberbbooth@panamericanlife.com16-May-03 11:00 
QuestionC# code? Pin
beavis17-Feb-03 20:04
memberbeavis17-Feb-03 20:04 
AnswerRe: C# code? Pin
fanell4-Mar-03 12:36
memberfanell4-Mar-03 12:36 
GeneralRe: C# code? Pin
princedom16-May-03 5:04
memberprincedom16-May-03 5:04 
GeneralRe: C# code? Pin
Anonymous24-May-03 12:42
sussAnonymous24-May-03 12:42 
GeneralRe: C# code? Pin
princedom19-May-03 8:33
memberprincedom19-May-03 8:33 
GeneralRe: C# code? Pin
Paul Evans2-Feb-04 6:24
memberPaul Evans2-Feb-04 6:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150427.4 | Last Updated 17 Feb 2003
Article Copyright 2003 by Thomas_fn
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid