aikeith Posted January 24, 2003 Posted January 24, 2003 Anyone know how to ping a server and get back up/down results using vb.net? Thanks. Quote
Datahighway Posted January 24, 2003 Posted January 24, 2003 (edited) Hi aikeith, try this. 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] Edited January 24, 2003 by Robby Quote
Moderators Robby Posted January 24, 2003 Moderators Posted January 24, 2003 In case you're not sure of which libraries to import... 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 Quote Visit...Bassic Software
Datahighway Posted January 24, 2003 Posted January 24, 2003 Hi Robby, i am a newbie in VB Dot. is my Solution wrong ? Or is there a better Soltution ? Regards Datahighway Quote
aikeith Posted January 24, 2003 Author Posted January 24, 2003 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!!! Quote
Moderators Robby Posted January 24, 2003 Moderators Posted January 24, 2003 Datahighway, Your solution was correct, you forgot to include the Imports. If you look closely, I copy/pasted your code. Quote Visit...Bassic Software
*Gurus* divil Posted January 24, 2003 *Gurus* Posted January 24, 2003 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 Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Incubus Posted February 18, 2003 Posted February 18, 2003 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? Quote
*Experts* Volte Posted February 18, 2003 *Experts* Posted February 18, 2003 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. Quote
Incubus Posted February 18, 2003 Posted February 18, 2003 Thanks, I forgot for a moment that it's possible with VS.NET to combine different languages in a program. Quote
lundholm Posted April 21, 2003 Posted April 21, 2003 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 Quote
michaelangelo Posted April 26, 2003 Posted April 26, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.