Results 1 to 2 of 2

Thread: pinging a list of addresses...

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Galt, Ca
    Posts
    47

    pinging a list of addresses...

    i have a treeview which will contain names of sites pinged. When the form loads, i want to ping this list of sites to see which ones replies and which ones don't.


    the treeview looks like this...


    username
    Online
    ....yahoo
    ....hotmail
    Offline
    ....google
    ....lycos

    the node that says "Online" is called n1

    this is what i do to add one online site...

    call this sub

    Dim hFile As Long, lpWSAdata As WSAdata
    Dim hHostent As Hostent, AddrList As Long
    Dim Address As Long, rIP As String
    Dim OptInfo As IP_OPTION_INFORMATION
    Dim EchoReply As IP_ECHO_REPLY
    Call WSAStartup(&H101, lpWSAdata)
    If GetHostByName(hostname + String(64 - Len(hostname), 0)) <> SOCKET_ERROR Then
    CopyMemory hHostent.h_name, ByVal GetHostByName(hostname + String(64 - Len(hostname), 0)), Len(hHostent)
    CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
    CopyMemory Address, ByVal AddrList, 4
    End If
    hFile = IcmpCreateFile()
    If hFile = 0 Then
    strreply = "Unable to Create File Handle"
    Exit Sub
    End If
    OptInfo.TTL = 255
    If IcmpSendEcho(hFile, Address, String(32, "A"), 32, OptInfo, EchoReply, Len(EchoReply) + 8, 2000) Then
    rIP = CStr(EchoReply.Address(0)) + "." + CStr(EchoReply.Address(1)) + "." + CStr(EchoReply.Address(2)) + "." + CStr(EchoReply.Address(3))
    Else
    strreply = "Timeout"
    End If
    If EchoReply.Status = 0 Then
    strreply = "yes"
    Else
    strreply = "Failure ..."
    End If
    Call IcmpCloseHandle(hFile)
    Call WSACleanup

    then, i add them based on what "strreply" is


    so i have

    Private Sub Form_Load()

    Set n1 = TreeView1.Nodes.Add(, 1, "new", "new", 2, 2)
    n1.Bold = True
    n1.Text = "Online"

    const hostname = "www.yahoo.com"
    call ping
    if strreply = "yes" then

    treeview1.nodes.add(n1, 4, [key], [text])="Yahoo.com"
    end if

    Now finally the question....

    when i use a loop or a for statement to run the ping sub over again, i need to change const hostname to the name of the different sites (of course) but, when i do that vb tells me:

    compile error duplicate declaration in current scope

    how can i get rid of this?

    -emptywords

  2. #2
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    do use a constant, at the top of your form/module put this

    make sure the sub and form_load are in the same module, otherwise, you must change it to Public

    Code:
    Private hostname As String
    if your loop, set hostname=whatever

    or you could pass hostname as a parameter to the ping sub

    change
    Code:
    Function ping() As String
    
    To 
    
    Function ping(hostname) As String
    and then in your loop:

    Code:
    ping(whatever)
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width