How to check if Network PC is online
Guys, how do I check if a PC connected to a network is online?
I created a program that will distribute a file to all IP addresses given.
My problem is, when the user gives an IP that is offline (turned off or not connected to the network), the program hangs for a few seconds while executing the FileCopy procedure then returns an error that the path can't be found.
I wanted to prevent the hang up and I think I can do that by checking first if the IP is online before going to the FileCopy procedure.
Thanks a lot guys!
Re: How to check if Network PC is online
Re: How to check if Network PC is online
Quote:
Originally Posted by HoraShadow
Ping the IP?
Good idea.. How do I do that in VB? :confused:
Re: How to check if Network PC is online
you could just connect to the IP on port 80. Port 80 will accept connections on most hosts.
so have a winsock on the form and use this
VB Code:
Winsock1.Connect strIP, 80
heres the Winsock Connect sub
VB Code:
Private Sub Winsock1_Connect()
'Connected! so the host must be online
Winsock1.Close 'Disconnect the socket & return to closed state
End Sub
The winsock error sub
VB Code:
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'Socket errored so it didnt connect - the host is not online
Winsock1.Close 'Return its state to closed
End Sub
Re: How to check if Network PC is online
the182guy: this works even if the PC don't have a VB program w/ winsock? as long as the PC is connected and online? thanks!
Re: How to check if Network PC is online
Quote:
Originally Posted by bulletrick
the182guy: this works even if the PC don't have a VB program w/ winsock? as long as the PC is connected and online? thanks!
the computer that your trying to find out the online status of does not need any vb app on it.
Re: How to check if Network PC is online
Quote:
Originally Posted by the182guy
the computer that your trying to find out the online status of does not need any vb app on it.
Ok. thanks a lot! That's what I needed. Try it later. Thanks again! :wave:
Re: How to check if Network PC is online
Quote:
Originally Posted by bulletrick
Ok. thanks a lot! That's what I needed. Try it later. Thanks again! :wave:
alright no probs, post back if you have problems :thumb:
Re: How to check if Network PC is online
Hello 182guy!
Uhhh.. the code did not work...
Re: How to check if Network PC is online
did you set the IP? you should change the 'strIP' to the network target IP address
Re: How to check if Network PC is online
Quote:
Originally Posted by the182guy
did you set the IP? you should change the 'strIP' to the network target IP address
Hehe. Of course.. I know that. I used "192.0.1.170", 80.
Re: How to check if Network PC is online
you could get the list of connected terminals to the LAN, then you could check the list if the specified terminal is connected, I posted an example on how to do this here:
http://www.vbforums.com/showthread.php?t=391595