Ping using vb.net/asp.net

Hi aikeith,
try this.
Code:
        Dim tcpClient As New TcpClient()
        Dim myIP As IPAddress = IPAddress.Parse("192.168.0.254")
        Try
            You can change the Port 80 to whatever port you wish to hit (i.e.8080)
            tcpClient.Connect(myIP, 80)
            MessageBox.Show("Ping is OK")
        Catch err As Exception
            Do what you want in here if the ping is unsuccessful
            MessageBox.Show("Ping is not  OK")
        End Try

[edit]Changed < > tags to [ ] [/edit]
 
Last edited by a moderator:
In case youre not sure of which libraries to import...
Code:
        Dim tcpClient As New System.Net.Sockets.TcpClient()

        Dim myIP As System.Net.IPAddress = System.Net.IPAddress.Parse("192.168.0.254")
        Try
            You can change the Port 80 to whatever port you wish to hit (i.e.8080)
            tcpClient.Connect(myIP, 80)
            MessageBox.Show("Ping is OK")
        Catch err As Exception
            Do what you want in here if the ping is unsuccessful
            MessageBox.Show("Ping is not  OK")
        End Try
 
Both solutions are right. For the first one I would add:

Imports System.Net
Imports System.Net.Sockets

Then keep the rest the same (I did and it works!!)

Thanks for your help guys!!!
 
Datahighway, Your solution was correct, you forgot to include the Imports.

If you look closely, I copy/pasted your code.
 
VB.NET and C# are almost identical languages; the only thing largely
different about them is the syntax. It will not be hard to port that
code to VB.NET at all.

Alternatively, you could create a C# class project in your programs
solution, add that ping class, and then you will be able to use the C# class
from within your VB project.
 
the c#-translated code worked, but only once, as someone pointed out.

so i tried the short connection code above, but that just tells me that the other machine refused the connection.

All im tryna do is have a little programm telling me whcih machines on my network are on, and if i have access to the internet through it.

It works once with the long code, but not at all on the short one. any ids?


cheerza


emile
 
Back
Top