Jump to content

Ping to Website using VB6.0

- - - - -

  • Please log in to reply
4 replies to this topic

#1
gyswamy

gyswamy

    Newbie

  • Members
  • Pip
  • 2 posts
Hi All,

I want to know How to Ping Website using VB6.0 programing with code? I am searching since 10 days in google. I have not got any code so far. Please help me if any one knows.

Thanks in Advance.:cursing:

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 856 posts
  • Location:Arkansas
From this webpage:
Ping from VB6 - VBForums

They suggest this code:

Public Function ComputerIsOnline(ByVal strComputerName As String) As Boolean

    On Error GoTo ErrorHandler

    

    Dim strResult   As String

    Dim ShellX      As String

    Dim FileNum     As Integer

    Dim lPid        As Long

    Dim lHnd        As Long

    Dim lRet        As Long

    

    'DoEvents

    ShellX = Shell("command.com /c ping -n 2 " & strComputerName & " > log.txt", vbHide)

    lPid = ShellX

    If lPid <> 0 Then

        lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)

        If lHnd <> 0 Then

            lRet = WaitForSingleObject(lHnd, INFINITE)

            CloseHandle (lHnd)

        End If

        FileNum = FreeFile

        Open "log.txt" For Input As #FileNum

        strResult = Input(LOF(1), 1)

        Close #FileNum

        ComputerIsOnline = (InStr(strResult, "Lost = 0") > 0)

    End If

    Exit Function

ErrorHandler:

    ComputerIsOnline = False

    Exit Function

End Function

or this:

Private Declare Function GetRTTAndHopCount _

    Lib "iphlpapi.dll" _

   (ByVal lDestIPAddr As Long, _

    ByRef lHopCount As Long, _

    ByVal lMaxHops As Long, _

    ByRef lRTT As Long) As Long

        

Private Declare Function inet_addr _

    Lib "wsock32.dll" _

   (ByVal cp As String) As Long

 

 


Public Function Ping(prmIPaddr As String) As Boolean

Dim IPaddr As Long, HopsCount As Long, RTT As Long

Dim MaxHops As Long

    Const SUCCESS = 1

    MaxHops = 20               ' should be enough ...

    IPaddr = inet_addr(prmIPaddr)

    Ping = (GetRTTAndHopCount(IPaddr, HopsCount, MaxHops, RTT) = SUCCESS)

End Function


Give one of those a try and see if it works.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
gyswamy

gyswamy

    Newbie

  • Members
  • Pip
  • 2 posts
Thanks for Reply,

I am beginer in VB6.0. I used your code in my example.but it's showing compile error at "Synchronize" variable not defined..So Should we add any reference to project? And I have one doubt in that program what is that mean --

Public Function ComputerIsOnline(ByVal strComputerName As String) As Boolean

This is Function you are using..here you are sending computername as argument..But i want to ping to one website like "google.com". So Can i pass "google.com" in place of this argument?
I am waithing for your replay..

Thank you..:w00t:

#4
Mark Wylde

Mark Wylde

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Define the variable at the top of your code:
Const SYNCHRONIZE = &H100000

I think you should be able to use an IP address or host name in that function anyway. Shouldn't make much difference.

#5
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 856 posts
  • Location:Arkansas
The ComputerIsOnline function is just someone else's version of the ping function. The name of the function is not important. You should be able to pass in a URL to the function for strComputerName with no problems. I'm not fluent in VB, but I just wanted to post what I found from searching in case it helps.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users