C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Internet ConnectionStatus and NetworkConnection Type


Posted Date: 14 Feb 2008    Resource Type: Code Snippets    Category: Network

Posted By: Danasegarane.A       Member Level: Diamond
Rating:     Points: 10



This code will check for the avaliability of the following network connection
1.Internet connection status
2.Lan connection type



'In a Class module
Public Class CheckInternetConnectionType
'**************************************
' Name: Check internet connection status and LanConnection type
' This code makes API calls to check for an internet conection and
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
Public Declare Function IsNetworkAlive Lib "SENSAPI.dll" (ByRef lpdwFlags As Long) As Long
Private Const NETWORK_ALIVE_LAN As Integer = &H1
Private Const NETWORK_ALIVE_WAN As Integer = &H2

'Function to check for the internet connected or not
Public Function IsConnected() As Boolean
'Returns true if there is any internet connection.
IsConnected = InternetGetConnectedState(0, 0)
End Function

'Function to check the lan Connection type
Public Function ConnectionType() As String
Dim ret As Long
If IsNetworkAlive(ret) > 0 Then
'If the Network connection is found then it will return a value a greater than zero
ConnectionType = IIf(ret = NETWORK_ALIVE_LAN, "Connected Via LAN", "Connected Via WAN")
Else
ConnectionType = "Not connected to Lan"
End If
End Function

'Usage
' In a Form add a button and in the click event code this
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Private CheckConn As New CheckInternetConnectionType()
'Prints true if connected to Internet ,False when not connected
console.WriteLine(CheckInternetConnectionType.IsConnected)
'Prints Lan or Wan
console.WriteLine(CheckInternetConnectionType.ConnectionType)
End Sub
End Class







Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Verify user credentials using API
Previous Resource: How to get ping in milliseconds
Return to Discussion Resource Index
Post New Resource
Category: Network


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween mask

Contact Us    Privacy Policy    Terms Of Use