03-26-2013, 09:57 AM
Checking if the computer is conected to the internet:
[code2=vbnet]If My.Computer.Network.IsAvailable = True Then
MsgBox("Your computer is conected", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Information")
Else
MsgBox("Your computer is not conected", MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical, "Information")
End If[/code2]
Pinging a host:
First import System.Net and System.Net.NetworkInformation:
[code2=vbnet]Imports System.Net, System.Net.NetworkInformation[/code2]
Then ping with the folowing code:
[code2=vbnet]Sub Ping()
Dim ping As New Ping()
Dim reply As PingReply
Dim _byte As Byte() = BitConverter.GetBytes(32)
Try
reply = ping.Send(Host, 1000, _byte)
Select Case reply.Status
Case IPStatus.Success
' code for succesfull ping
Case IPStatus.TimedOut
' code for ping timeout
Case IPStatus.BadDestination
'code for bad adress
Case Else
'code for other ocurences
' you can put a MsgBox that will say that something else happened
'MsgBox("Please check code", MsgBoxStyle.Exclamation, "Ping Status")
End Select
Catch pex As PingException
MsBox(pex.ToString)
Exit Sub
Catch ex As Exception
MsgBox(ex.ToString)
End Try[/code2]
Now before you reply to this post saying that the code above does not work replace "Host" with the actual ip of the web site.
For the third problem , checking if MySql server is online or not, that is also simple because usualy MySql has a default port number and its just a case of connecting a TcpClient to that ip and port and if it connects it means it is online.
Here are the steps to do just that:
First , just as above import System.Net And System.Net.Sockets(i'm not going to show how to do it again)
Second Use this code snippet:
[code2=vbnet]Private Sub CheckServerStatus()
Try
Dim TcpCl As New TcpClient
Dim IpEP As New IPEndPoint(IPAddress.Parse("IP"), 3306) 'if i'm not mistaking 3306 is the default port for Mysql Server
TcpCl.Connect(IpEP)
If TcpCl.Connected Then
'code for serve online
TcpCl.Close()
End If
Catch ex As Exception
'code for server offline
End Try
End Sub[/code2]
Replace "IP" with the ip of the server you are trying to connect. REMEMBER THE "IP" HAS TO BE A STRING !!!
[code2=vbnet]If My.Computer.Network.IsAvailable = True Then
MsgBox("Your computer is conected", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Information")
Else
MsgBox("Your computer is not conected", MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical, "Information")
End If[/code2]
Pinging a host:
First import System.Net and System.Net.NetworkInformation:
[code2=vbnet]Imports System.Net, System.Net.NetworkInformation[/code2]
Then ping with the folowing code:
[code2=vbnet]Sub Ping()
Dim ping As New Ping()
Dim reply As PingReply
Dim _byte As Byte() = BitConverter.GetBytes(32)
Try
reply = ping.Send(Host, 1000, _byte)
Select Case reply.Status
Case IPStatus.Success
' code for succesfull ping
Case IPStatus.TimedOut
' code for ping timeout
Case IPStatus.BadDestination
'code for bad adress
Case Else
'code for other ocurences
' you can put a MsgBox that will say that something else happened
'MsgBox("Please check code", MsgBoxStyle.Exclamation, "Ping Status")
End Select
Catch pex As PingException
MsBox(pex.ToString)
Exit Sub
Catch ex As Exception
MsgBox(ex.ToString)
End Try[/code2]
Now before you reply to this post saying that the code above does not work replace "Host" with the actual ip of the web site.
For the third problem , checking if MySql server is online or not, that is also simple because usualy MySql has a default port number and its just a case of connecting a TcpClient to that ip and port and if it connects it means it is online.
Here are the steps to do just that:
First , just as above import System.Net And System.Net.Sockets(i'm not going to show how to do it again)
Second Use this code snippet:
[code2=vbnet]Private Sub CheckServerStatus()
Try
Dim TcpCl As New TcpClient
Dim IpEP As New IPEndPoint(IPAddress.Parse("IP"), 3306) 'if i'm not mistaking 3306 is the default port for Mysql Server
TcpCl.Connect(IpEP)
If TcpCl.Connected Then
'code for serve online
TcpCl.Close()
End If
Catch ex As Exception
'code for server offline
End Try
End Sub[/code2]
Replace "IP" with the ip of the server you are trying to connect. REMEMBER THE "IP" HAS TO BE A STRING !!!
Sssssssssoftware developer...