Network Topics include: sockets, protocols and the web

Go Back  Xtreme .NET Talk > .NET > Network > Ping using vb.net/asp.net


Reply
 
Thread Tools Display Modes
  #1  
Old 01-24-2003, 10:20 AM
aikeith aikeith is offline
Freshman
 
Join Date: Jan 2003
Posts: 49
aikeith is on a distinguished road
Default Ping using vb.net/asp.net

Anyone know how to ping a server and get back up/down results using vb.net?

Thanks.
Reply With Quote
  #2  
Old 01-24-2003, 02:02 PM
Datahighway Datahighway is offline
Guest

Preferred language:
VB .NET
 
Join Date: Jul 2002
Location: Germany
Posts: 44
Datahighway is on a distinguished road
Default

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 [ ]

Last edited by Robby; 01-24-2003 at 02:13 PM.
Reply With Quote
  #3  
Old 01-24-2003, 02:19 PM
Robby's Avatar
Robby Robby is offline
Ultimate Contributor
 
Join Date: Nov 2002
Location: Montreal, Ca.
Posts: 3,461
Robby is on a distinguished road
Default

In case you're 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
__________________
Visit...Bassic Software
Reply With Quote
  #4  
Old 01-24-2003, 03:07 PM
Datahighway Datahighway is offline
Guest

Preferred language:
VB .NET
 
Join Date: Jul 2002
Location: Germany
Posts: 44
Datahighway is on a distinguished road
Default

Hi Robby,

i am a newbie in VB Dot. is my Solution wrong ?
Or is there a better Soltution ?

Regards Datahighway
Reply With Quote
  #5  
Old 01-24-2003, 03:12 PM
aikeith aikeith is offline
Freshman
 
Join Date: Jan 2003
Posts: 49
aikeith is on a distinguished road
Default

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!!!
Reply With Quote
  #6  
Old 01-24-2003, 03:23 PM
Robby's Avatar
Robby Robby is offline
Ultimate Contributor
 
Join Date: Nov 2002
Location: Montreal, Ca.
Posts: 3,461
Robby is on a distinguished road
Default

Datahighway, Your solution was correct, you forgot to include the Imports.

If you look closely, I copy/pasted your code.
__________________
Visit...Bassic Software
Reply With Quote
  #7  
Old 01-24-2003, 03:44 PM
Datahighway Datahighway is offline
Guest

Preferred language:
VB .NET
 
Join Date: Jul 2002
Location: Germany
Posts: 44
Datahighway is on a distinguished road
Default

Hi Robby,

OK, Sorry my Mistake.
Reply With Quote
  #8  
Old 01-24-2003, 04:39 PM
divil's Avatar
divil divil is offline
Ultimate Contributor
 
Join Date: Nov 2002
Location: England
Posts: 2,747
divil is on a distinguished road
Default

That's not a ping. You can create a real ICMP ECHO packet and send it with the .NET framework and the Socket class, see the URL below for an application written in C# to do this.

ICMP Ping using .NET Framework
__________________
MVP, Visual Developer - .NET

Now you see why evil will always triumph - because good is dumb.

My free .NET Windows Forms Controls and Articles
Reply With Quote
  #9  
Old 02-18-2003, 08:22 AM
Incubus Incubus is offline
Newcomer

Preferred language:
VB.Net
 
Join Date: Feb 2003
Location: Netherlands
Posts: 2
Incubus is on a distinguished road
Default

Quote:
Originally posted by divil
That's not a ping. You can create a real ICMP ECHO packet and send it with the .NET framework and the Socket class, see the URL below for an application written in C# to do this.

ICMP Ping using .NET Framework
But how do you write a ping command with VB.NET?
Reply With Quote
  #10  
Old 02-18-2003, 08:47 AM
Volte Volte is offline
Neutiquam Erro

Preferred language:
C# and VB.NET
 
Join Date: Nov 2002
Posts: 2,171
Volte is on a distinguished road
Default

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 program's
solution, add that ping class, and then you will be able to use the C# class
from within your VB project.
Reply With Quote
  #11  
Old 02-18-2003, 11:27 AM
Incubus Incubus is offline
Newcomer

Preferred language:
VB.Net
 
Join Date: Feb 2003
Location: Netherlands
Posts: 2
Incubus is on a distinguished road
Default

Thanks, I forgot for a moment that it's possible with VS.NET to combine different languages in a program.
Reply With Quote
  #12  
Old 04-21-2003, 04:35 AM
lundholm lundholm is offline
Newcomer

Preferred language:
VB
 
Join Date: Apr 2003
Location: Sweden
Posts: 1
lundholm is on a distinguished road
Question

Hi..

I´m a bit lost i VS... I get a errormessage when using tcpClient.Connect(myIP, 80)

It says:
An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll

Additional information: Request for the permission of type System.Net.SocketPermission, System,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

What is wrong?

Vr Mikael
Reply With Quote
  #13  
Old 04-26-2003, 09:36 AM
michaelangelo michaelangelo is offline
Newcomer
 
Join Date: Apr 2003
Posts: 2
michaelangelo is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ping Class - Assinchronous ping teixeira Network 2 08-29-2006 09:34 AM
ASP.NET and VB.NET/C#.net that allow a user to send SMS to a Mob.Number. sureshcd10 ASP.NET 0 05-09-2004 03:40 AM

Advertisement:

Powered by liquidweb