Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




IsDestinationReachable


Hi,

I'm having a Problem with the API "IsDestinationReachable". I'm using the following code to determin if a computer is online or not:


Code:
Private Declare Function IsDestinationReachable Lib _
"Sensapi.dll" Alias "IsDestinationReachableA" _
(ByVal lpszDestination As String, _
lpQOCInfo As QOCINFO) As Long

Private Type QOCINFO
dwSize As Long
dwFlags As Long
dwInSpeed As Long
dwOutSpeed As Long
End Type

Code:
Public Function Ping(ByVal IP As String) As Boolean
Dim QuestStruct As QOCINFO
Dim lReturn As Long

QuestStruct.dwSize = Len(QuestStruct)

lReturn = IsDestinationReachable(IP, QuestStruct)

If lReturn = 1 Then
Ping = True
Else
Ping = False
End If
End Function

As long as I "ping" with an UNC name everything works fine, I get True when the computer is online, False when it is offline.

But when I "ping" with an IP address I allways get back True. The only way I get back False is to unplug the network cable.

Now the problem is, I have to ping with the IP address.

Is this kind ov behavior normal? Can anybody help?

Michael




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Isdestinationreachable Returning False Positives...
OK I'm at a loss here, I'm trying to simply determine if a computer is on the LAN with the following code:

Private Declare Function IsDestinationReachable Lib "SENSAPI.DLL" Alias "IsDestinationReachableA" (ByVal lpszDestination As String, ByRef lpQOCInfo As QOCINFO) As Long

Const NETWORK_ALIVE_AOL = &H4
Const NETWORK_ALIVE_LAN = &H1
Const NETWORK_ALIVE_WAN = &H2
Private Type QOCINFO
dwSize As Long
dwFlags As Long
dwInSpeed As Long 'in bytes/second
dwOutSpeed As Long 'in bytes/second
End Type

Private Sub cmdcheckip_Click()
Dim Ret As QOCINFO
Ret.dwSize = Len(Ret)


If IsDestinationReachable(txtcompname.Text, Ret) = 0 Then
MsgBox "The destination cannot be reached."
Else
MsgBox "Machine " & txtcompname.Text & " was reached."
End If
End Sub




Private Sub cmdexit_Click()
Unload Me
End Sub


Trouble is, with a lot of valid computer names it is still responding! If I put in some arbitrary name it returns false, so it seems like it is kind of working, but for a number of machines I have tested it on it will return true even if they are off! Anybody have any ideas?
Tom

Does 'IsDestinationReachable' API Call Support Network Address Translation
Hi,

Could anybody please tell me if they know if 'IsDestinationReachable' API call support Network Address Translation ?
I have written a program in VB6 that needs to PING numerous PC's prior to mapping.

I am passing the IP address and QOCINFO as parameters for 'IsDestinationReachable', which works fine for the PC's not on the NAT'd network.

However the PING fails if the PC is using Network Address Translation.
I can ping the NAT'd IP address using the PING command, from the cmd prompt on my PC, so I know that the destination is reachable.

Any help would be very much appreciated on resolving this matter.

The code needs to be written in VB6.

Thanks in advance.

Copyright 2005-08 www.BigResource.com, All rights reserved