[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

NETSTAT With GUI. How?

Posted on 2006-05-10
16
Medium Priority
?
658 Views
Last Modified: 2008-01-09
Hello experts,

I'd like to build a NETSTAT like program. If any of you already have a few samples for me to look at and learn from it I'd really apreciate it. I believe this is what the program should do...

1. Declare IP address to be used as a match.
2. Go through a list of IP address that are currently connected to local computer.
2.1 If Declared IP address is found and its connection state is equal to ESTABLISHED then MsgBox"Connected!"

I do have .NET 2.0 if makes any difference.

Hope my question makes sense.

PS: I'm only looking for VB.NET samples and not already existing freeware or shareware software....
0
Comment
Question by:donniedarko801
  • 9
  • 7
16 Comments
 
LVL 9

Expert Comment

by:sk33v3
ID: 16652027
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
        Dim connections As TcpConnectionInformation() = properties.GetActiveTcpConnections()

        Dim t As TcpConnectionInformation
        For Each t In connections
            Me.RichTextBox1.AppendText(t.LocalEndPoint.Address.ToString & ":" & t.LocalEndPoint.Port & vbTab & t.RemoteEndPoint.Address.ToString & ":" & t.RemoteEndPoint.Port & vbCrLf)
           
        Next t

    End Sub

Requires you to have a richtextbox on your form.
0
 
LVL 9

Expert Comment

by:sk33v3
ID: 16652035
Sorry forgot the imports statement for you

Imports System.Net.NetworkInformation
0
 
LVL 1

Author Comment

by:donniedarko801
ID: 16652162
wow! thx for the reply. About the text box... no need to. You can declare it as a variable.

str_IP = "10.10.1.5"

Mind reposting updated version? Thank you very much!
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
LVL 9

Accepted Solution

by:
sk33v3 earned 2000 total points
ID: 16652215
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
        Dim connections As TcpConnectionInformation() = properties.GetActiveTcpConnections()


        Dim t As TcpConnectionInformation
        For Each t In connections
            ''Me.RichTextBox1.AppendText(t.LocalEndPoint.Address.ToString & ":" & t.LocalEndPoint.Port & vbTab & t.RemoteEndPoint.Address.ToString & ":" & t.RemoteEndPoint.Port & vbCrLf)
            If t.RemoteEndPoint.Address.ToString = str_IP And t.State = TcpState.Established Then
                MsgBox("Found")
            End If
        Next t

    End Sub
0
 
LVL 1

Author Comment

by:donniedarko801
ID: 16652221
Also, I need the code to ignore Ports. Ports do not matter to me.

Again Thx so much!
0
 
LVL 1

Author Comment

by:donniedarko801
ID: 16652249
Your reposted updated version still has text box... Just pointing it out.
0
 
LVL 9

Expert Comment

by:sk33v3
ID: 16652274
The text box is commented out. That line was actually there not to read the IP address you wanted to monitor but to write out the entire Netstat.... However as I said, it is commented out.
0
 
LVL 1

Author Comment

by:donniedarko801
ID: 16652343
Ok... I'm not sure if I understand what you're doing since I can't see where is the replacement code for the commented out part.

How would you comare the rest of the code to:

str_IP = "10.10.1.5"

Sorry to ask so many questions...
0
 
LVL 1

Author Comment

by:donniedarko801
ID: 16652382
never mind! I think this is it! Sorry, I'm at work trying to figure this out in between phone calls.
0
 
LVL 1

Author Comment

by:donniedarko801
ID: 16652399
I think this is it!

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
Dim connections As TcpConnectionInformation() = properties.GetActiveTcpConnections()

str_IP = "10.10.1.5"
Dim t As TcpConnectionInformation
For Each t In connections
If t.RemoteEndPoint.Address.ToString = str_IP And t.State = TcpState.Established Then
MsgBox ("Found")
End If
Next t

End Sub
0
 
LVL 9

Expert Comment

by:sk33v3
ID: 16654565
Yes, and all you did was remove the commented code.
0
 
LVL 1

Author Comment

by:donniedarko801
ID: 16654738
Now that I got home and was able to paste the code into vb.net it comes up with errors.

Corrected code...

=========================================================================
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim properties As Net.NetworkInformation.IPGlobalProperties = Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
  Dim connections As Net.NetworkInformation.TcpConnectionInformation() = properties.GetActiveTcpConnections()
  Dim str_IP As String

  str_IP = "10.10.1.5"
  Dim t As Net.NetworkInformation.TcpConnectionInformation
  For Each t In connections
   If t.RemoteEndPoint.Address.ToString = str_IP And t.State = TcpState.Established Then
    MsgBox("Found")
   End If
  Next t

 End Sub

==========================================================================

Here's the last error...

 If t.RemoteEndPoint.Address.ToString = str_IP And t.State = TcpState.Established Then
    MsgBox("Found")

Error msg is "TcpState not declared"

Any ideas?


0
 
LVL 9

Expert Comment

by:sk33v3
ID: 16654830
Do you have this in the form code
Imports System.Net.NetworkInformation
0
 
LVL 1

Author Comment

by:donniedarko801
ID: 16654833
Found it again! This is tested and it works!

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim properties As Net.NetworkInformation.IPGlobalProperties = Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
  Dim connections As Net.NetworkInformation.TcpConnectionInformation() = properties.GetActiveTcpConnections()
  Dim str_IP As String

  str_IP = "10.10.1.5"
  Dim t As Net.NetworkInformation.TcpConnectionInformation
  For Each t In connections
   If t.RemoteEndPoint.Address.ToString = str_IP And t.State = System.Net.NetworkInformation.TcpState.Established Then
    MsgBox("Found")
   End If
  Next t

 End Sub
0
 
LVL 1

Author Comment

by:donniedarko801
ID: 16654842
Thank you so much!
0
 
LVL 9

Expert Comment

by:sk33v3
ID: 16654852
No problem.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

611 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question