Using Ping in VB6.0 ? 
Author Message
 Using Ping in VB6.0 ?

Hi,

Can somebody tell me how I can ping to another computer just to see
if that computer is still on the network ?

How can I do this in VB50 without using "ping.exe" ??

May thanks,
Karel



Sun, 22 Apr 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?
Check out
www.mvps.org/vbnet/

--
Ricky
ICQ# 4730537             EGN# 16191
kharjes at dgi dot net
http://www.geocities.com/~howdy
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Please Reply To The Newsgroups

Quote:

>Hi,

>Can somebody tell me how I can ping to another computer just to see
>if that computer is still on the network ?

>How can I do this in VB50 without using "ping.exe" ??

>May thanks,
>Karel



Sun, 22 Apr 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?

Karel,
Did  you try VB Shell commnad,
you can ping to another computer and check whether the computer is in
network by using following code

z = Shell("ping.exe 169.18.6.20", vbHide) 'use your own IP Address

if z> 0 then
    'computer is still on network
end if

--
RAJEESH .V.K.
http://members.tripod.com/~rajeesh/

Quote:

> Hi,

> Can somebody tell me how I can ping to another computer just to see
> if that computer is still on the network ?

> How can I do this in VB50 without using "ping.exe" ??

> May thanks,
> Karel



Sun, 29 Apr 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?

Quote:

>Karel,
>Did  you try VB Shell commnad,
>you can ping to another computer and check whether the computer is in
>network by using following code

>z = Shell("ping.exe 169.18.6.20", vbHide) 'use your own IP Address

>if z> 0 then
>    'computer is still on network
>end if

huh?  That will tell you only if Shell had an error or returned a process ID
Quote:
> 0.  It says nothing about the result of the PING.  You could use:

z = Shell(Environ$("comspec" & " /c ping.exe 169.18.6.20 > pingout.tmp",
vbHide)
Then wait for the PING process to finish and parse the contents of the
'pingout.tmp' file, but that's the only way Shell would be of use.

To do it in code you must call the routines in ICMP.DLL and for an example
of that see http://home.earthlink.net/~butlerbob/vb/network/tcpip/ping.htm



Sun, 29 Apr 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?

Bob Butler schrieb:

Quote:
> To do it in code you must call the routines in ICMP.DLL and for an example
> of that see http://home.earthlink.net/~butlerbob/vb/network/tcpip/ping.htm

Nice piece of code !!!
Very helpful to me, too !!!
Is there a way to make this routine do also a DNS-Lookup (resolving the full
name when entering an ipadress) ????

best regards

Frank



Mon, 30 Apr 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?
Quote:

>Bob Butler schrieb:
>> To do it in code you must call the routines in ICMP.DLL and for an
example
>> of that see

http://home.earthlink.net/~butlerbob/vb/network/tcpip/ping.htm

Quote:

>Is there a way to make this routine do also a DNS-Lookup (resolving the
full
>name when entering an ipadress) ????

If you mean that literally (user enters IP, you display hostname) then
that's a reverse-DNS lookup.  Usually the user enters a name and you need to
translate it to IP.  The regular DNS lookup is there in the NameLookup
function but I haven't ever looked at doing a reverse lookup.  It would
meanusing the GetHostByAddr cal instead of GetHostByName and should be
possible with relatively few tweaks to that code.


Mon, 30 Apr 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?

Bob Butler schrieb:

Quote:
> If you mean that literally (user enters IP, you display hostname) then
> that's a reverse-DNS lookup.  Usually the user enters a name and you need to
> translate it to IP.  The regular DNS lookup is there in the NameLookup
> function but I haven't ever looked at doing a reverse lookup.  It would
> meanusing the GetHostByAddr cal instead of GetHostByName and should be
> possible with relatively few tweaks to that code.

Sorry !!! I'm not an expert in calling .DLL funcions (yet). ;-)

Anybody got some spare time to implement the GetHostByAddr in this code ??

By the way: are there any problems to expect when running this routine under
VB5.0,  is it
necessary to use VB6.0 ???



Tue, 01 May 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?

Quote:

>Bob Butler schrieb:
>> meanusing the GetHostByAddr cal instead of GetHostByName and should be
>> possible with relatively few tweaks to that code.
>Sorry !!! I'm not an expert in calling .DLL funcions (yet). ;-)

I started looking at it last night but I haven't been able to get
GetHostByAddr working.  Some quick searches through dejanews indicates that
there may be some strange issues with the byte order of the IP address to
send to the call so I'll have to do some digging.  I will be ading this to
the code but can't guarantee when I'll have enough time to figure it out.
With luck, maybe over the weekend.


Tue, 01 May 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?

Quote:

>Bob Butler schrieb:
<cut>
>Anybody got some spare time to implement the GetHostByAddr in this code ??

>By the way: are there any problems to expect when running this routine
under
>VB5.0,  is it
>necessary to use VB6.0 ???

I figured out my problem (I had copied some code from an old VB3 app and
forgot to update the Declare for 32-bit...  just a stupid oversight on my
part).  Once I did that the gethostbyaddr call started working fine.  I
updated the page so that the NameLookup function now accepts a string with
either a hostname or an IP (standard dotted decimal format) and performs the
translation either direction.

http://home.earthlink.net/~butlerbob/vb/network/tcpip/ping.htm



Tue, 01 May 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?

Bob Butler schrieb:

Quote:
> I figured out my problem (I had copied some code from an old VB3 app and
> forgot to update the Declare for 32-bit...  just a stupid oversight on my
> part).  Once I did that the gethostbyaddr call started working fine.  I
> updated the page so that the NameLookup function now accepts a string with
> either a hostname or an IP (standard dotted decimal format) and performs the
> translation either direction.

> http://home.earthlink.net/~butlerbob/vb/network/tcpip/ping.htm

SMOOOOOOOTHHHHHH!!!!!!

Great stuff !!! Works fine on NT4.0 and W95 !!! Thank you , Bob !!!!

Once the routine ist started, can it be interrupted on a keypress (i.e. pinging
the whole subnet 1-255 in a loop and interrupt by pressing ESC) ??

Where can I find a documentation about all the routines included in the ICMP.DLL
(I want to figure out other options by myself) ???

best regards

Frank



Fri, 04 May 2001 03:00:00 GMT  
 Using Ping in VB6.0 ?

Bob Butler schrieb:

Quote:
> I figured out my problem (I had copied some code from an old VB3 app and
> forgot to update the Declare for 32-bit...  just a stupid oversight on my
> part).  Once I did that the gethostbyaddr call started working fine.  I
> updated the page so that the NameLookup function now accepts a string with
> either a hostname or an IP (standard dotted decimal format) and performs the
> translation either direction.

> http://home.earthlink.net/~butlerbob/vb/network/tcpip/ping.htm

One more question:

This routine delivers one ipadress and one hostname, which changes do I have to
make to the NameLookup subfunction to make it give back ALL hostnames (i.e. our
mailservers have up to 10 names) and all ipadresses (some routers have more than
one) of the specified host ???

Here is the complete NameLookup subfunction:

Function NameLookup(strName As String) As String
     ' routine to convert hostname to IP
     ' this routine actually gets all known aliases
     ' and IP addresses but only returns the first IP
     Dim x As Long ' scratch
     Dim nbytes As Long
     Dim strTarget As String ' null-delimited hostname
     Dim lngHostEnt As Long ' address of hostent structure
     Dim lngHEName As Long ' address of name pointer
     Dim lngHEAlias As Long ' address of alias pointer
     Dim lngHEAddress As Long ' address of address pointer
     Dim lngIPpointer As Long ' address of IP address
     Dim lngAPointer As Long ' address of Alias

     Dim intAliasCount As Long
     Dim intAddressCount As Long
     Dim strIP() As String
     Dim strAlias() As String
     Dim strAddress() As String

     'default values
     intAliasCount = 0
     intAddressCount = 0
     NameLookup = ""
     strTarget = strName & vbNullChar
     Debug.Print "Resolve: " & strName
     lngHostEnt = gethostbyname(strTarget) ' do actual winsock call
     If lngHostEnt = 0 Then
       NameLookup = 0
       Exit Function ' failed!
     End If
     lngHEName = lngHostEnt ' set pointer addresses
     lngHEAlias = lngHostEnt + 4
     lngHEAddress = lngHostEnt + 12
     ' convert addresses of pointers to the pointers...
     CopyMemory lngHEName, ByVal lngHEName, 4
     CopyMemory lngHEAlias, ByVal lngHEAlias, 4
     CopyMemory lngHEAddress, ByVal lngHEAddress, 4

     ' Get resolved hostname
     nbytes = lstrlen(ByVal lngHEName)
     If nbytes > 0 Then
       strName = Space$(nbytes)
       CopyMemory ByVal strName, ByVal lngHEName, nbytes
     Debug.Print "Full name: " & strName
     End If

     ' get all IP addresses
     CopyMemory lngIPpointer, ByVal lngHEAddress, 4
     Do While lngIPpointer ' end-of-list is null pointer
       ReDim Preserve strAddress(intAddressCount + 1)
       strAddress(intAddressCount) = Space$(4)
       CopyMemory ByVal strAddress(intAddressCount), ByVal lngIPpointer, 4
     Debug.Print "IP address " & CStr(intAddressCount) & _
       ": " & IPToText(strAddress(intAddressCount))
       CopyMemory ByVal lngHEAddress, 0&, 4 ' null for next call
       intAddressCount = intAddressCount + 1
       ' move to next IP
       lngHEAddress = lngHEAddress + 4
       CopyMemory lngIPpointer, ByVal lngHEAddress, 4
     Loop

     ' get any/all aliases
     CopyMemory lngAPointer, ByVal lngHEAlias, 4
     Do While lngAPointer ' end-of-list is a null
       ReDim Preserve strAlias(intAliasCount + 1)
       nbytes = lstrlen(ByVal lngAPointer)
       strAlias(intAliasCount) = Space$(nbytes)
       CopyMemory ByVal strAlias(intAliasCount), ByVal lngAPointer, nbytes
     Debug.Print "Alias " & CStr(intAliasCount) & ": " & _
       strAlias(intAliasCount)
       CopyMemory ByVal lngHEAlias, 0&, 4
       intAliasCount = intAliasCount + 1
       ' move to next IP
       lngHEAlias = lngHEAlias + 4
       CopyMemory lngAPointer, ByVal lngHEAlias, 4
     Loop

     If intAddressCount > 0 Then
       ' success
       NameLookup = IPToText(strAddress(0))
     Else
       NameLookup = "" ' weird!
     End If
     End Function



Fri, 18 May 2001 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Using Ping in VB6.0 ?

2. Using Ping in VB6.0 ?

3. Using Ping in VB6.0 ?

4. Ping function in VB6

5. PING, Is there an API (or other method) to call ping from VB

6. Ping writing ping component voor asp

7. API for PING in vb6

8. Pinging another host in VB6

9. VB6 Ping

10. PINGing with VB6

11. Using ping....

12. using a ping response for conditional behaviour under visual basic

 

 
Powered by phpBB® Forum Software