Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by Robby
  • Moderators
Posted

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

Visit...Bassic Software
Posted

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!!!

  • 4 weeks later...
  • *Experts*
Posted

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.

  • 2 months later...
Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...