How to check if network status is offline/limited(lan only)/online

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am just starting with VB. first thing i want to try is a small program that will display the computers network status. Is the network connection limited (LAN Only) Online (Lan and Internet) or Offline. i want a label that displays as
  • Status: Limited (Yellow Text)
  • Status: Online (Green Text)
  • Status: Offline (Red Text)
I have managed to get Online and offline status to work but not differentiate between limited or offline status.
Just to make it a bit more interesting i would also like to have the label flash. I have managed to get the flash to work but not in the right colours.
My Current code is Public Class MAINFORM
Dim NetStatus As String

Public Sub tmrBlink1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrBlink1.Tick
If tmrBlink1.Tag = True Then
lblStatus.ForeColor = Color.Green
tmrBlink1.Tag = False
Else
lblStatus.ForeColor = Color.Black
tmrBlink1.Tag = True
End If
End Sub

Private Sub MAINFORM_Load(sender As Object, e As EventArgs) Handles MyBase.Load

setup blink timer
tmrBlink1.Interval = 500
tmrBlink1.Enabled = True
tmrBlink1.Start()

Checks if there is a network connection and displays it along bottom of screen
If My.Computer.Network.IsAvailable = True Then
NetStatus = "STATUS: ONLINE"
lblStatus.ForeColor = Color.Green
lblStatus.Text = NetStatus
Else
NetStatus = "STATUS: OFFLINE"
lblStatus.Text = NetStatus
lblStatus.ForeColor = Color.Red
End If
End Sub
Hopefully i have described what i am trying to do clearly enough, and in the right forum
Thanks in advance

View the full article
 
Back
Top