 |
| Network Topics include: sockets, protocols and the web |
 |

01-24-2003, 10:20 AM
|
|
Freshman
|
|
Join Date: Jan 2003
Posts: 49
|
|
Ping using vb.net/asp.net
|
|
Anyone know how to ping a server and get back up/down results using vb.net?
Thanks.
|
|

01-24-2003, 02:02 PM
|
|
Guest
Preferred language: VB .NET
|
|
Join Date: Jul 2002
Location: Germany
Posts: 44
|
|
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.
|

01-24-2003, 02:19 PM
|
 |
Ultimate Contributor
|
|
Join Date: Nov 2002
Location: Montreal, Ca.
Posts: 3,461
|
|
|
|
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
|
|

01-24-2003, 03:07 PM
|
|
Guest
Preferred language: VB .NET
|
|
Join Date: Jul 2002
Location: Germany
Posts: 44
|
|
Hi Robby,
i am a newbie in VB Dot. is my Solution wrong ?
Or is there a better Soltution ?
Regards Datahighway
|
|

01-24-2003, 03:12 PM
|
|
Freshman
|
|
Join Date: Jan 2003
Posts: 49
|
|
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!!!
|
|

01-24-2003, 03:23 PM
|
 |
Ultimate Contributor
|
|
Join Date: Nov 2002
Location: Montreal, Ca.
Posts: 3,461
|
|
Datahighway, Your solution was correct, you forgot to include the Imports.
If you look closely, I copy/pasted your code.
|
|

01-24-2003, 03:44 PM
|
|
Guest
Preferred language: VB .NET
|
|
Join Date: Jul 2002
Location: Germany
Posts: 44
|
|
Hi Robby,
OK, Sorry my Mistake.
|
|

01-24-2003, 04:39 PM
|
 |
Ultimate Contributor
|
|
Join Date: Nov 2002
Location: England
Posts: 2,747
|
|
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
|
|

02-18-2003, 08:22 AM
|
|
Newcomer
Preferred language: VB.Net
|
|
Join Date: Feb 2003
Location: Netherlands
Posts: 2
|
|
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?
|
|

02-18-2003, 08:47 AM
|
|
Neutiquam Erro
Preferred language: C# and VB.NET
|
|
Join Date: Nov 2002
Posts: 2,171
|
|
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.
|
|

02-18-2003, 11:27 AM
|
|
Newcomer
Preferred language: VB.Net
|
|
Join Date: Feb 2003
Location: Netherlands
Posts: 2
|
|
Thanks, I forgot for a moment that it's possible with VS.NET to combine different languages in a program.
|
|

04-21-2003, 04:35 AM
|
|
Newcomer
Preferred language: VB
|
|
Join Date: Apr 2003
Location: Sweden
Posts: 1
|
|
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
|
|

04-26-2003, 09:36 AM
|
|
Newcomer
|
|
Join Date: Apr 2003
Posts: 2
|
|
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
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |
|
|
|
 |
|