Checking links

Discussion in 'ASP General' started by Harag, Sep 13, 2003.

  1. Harag

    Harag Guest

    Hi all

    win 2k pro
    sql server 2k
    asp - vbscript


    I got the below code from somewhere ages ago. I have a list of links
    on my site that link to other sites but I want to check if the link is
    a valid link automatically and if it fails after x checks (checks
    every 7 days) then to mark the link as a possible broken link

    the below seems to take ages to process and was wondering if there is
    a better way to do the below.

    thanks for any help & tips.

    Al


    Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
    on error resume next
    xmlhttp.open "get", sURL, False
    xmlhttp.send
    if err.number = 0 then
    iStatus = xmlhttp.Status
    else
    'error might be "DNS error"
    iStatus = 404
    end if
    on error goto 0
    Set xmlhttp = nothing

    ' if status =200 then it is a VALID url.
    if iStatus = 200 then
    ' valid link
    ' update db here
    else
    ' invalid link.
    ' update db
    end if
     
    Harag, Sep 13, 2003
    #1
    1. Advertising

  2. Harag

    dlbjr Guest

    UseWMI and impersonate a ping on the url.
    This will clarify if the site is up or down without sending the page itself.



    Function GetPing(strTarget)

    GetPing = False

    On Error resume Next

    set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery
    ("select * from Win32_PingStatus where address = '" & strTarget & "'")

    For Each o In oPing

    sResp = o.StatusCode

    Next

    If Len(sResp) > 0 Then

    if sResp = 0 Then

    GetPing = True

    End If

    End If

    set oPing = Nothing

    End Function



    -dlbjr

    invariable unerring alien
     
    dlbjr, Sep 13, 2003
    #2
    1. Advertising

  3. Harag

    Harag Guest

    Thanks for the code below.

    It quicker than my previous code but its still taking about 4-5
    seconds per link... but I think thats the nature of the net these
    days.

    thanks again.
    Al

    On Sat, 13 Sep 2003 13:19:23 -0500, "dlbjr" <> wrote:

    >UseWMI and impersonate a ping on the url.
    >This will clarify if the site is up or down without sending the page itself.
    >
    >
    >
    >Function GetPing(strTarget)
    >
    >GetPing = False
    >
    >On Error resume Next
    >
    >set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery
    >("select * from Win32_PingStatus where address = '" & strTarget & "'")
    >
    >For Each o In oPing
    >
    >sResp = o.StatusCode
    >
    >Next
    >
    >If Len(sResp) > 0 Then
    >
    >if sResp = 0 Then
    >
    >GetPing = True
    >
    >End If
    >
    >End If
    >
    >set oPing = Nothing
    >
    >End Function
    >
    >
    >
    >-dlbjr
    >
    >invariable unerring alien
    >
     
    Harag, Sep 14, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. www.westerncartooncards.ca

    Exchange Links < Western Cartoon Cards > Exchange Links

    www.westerncartooncards.ca, Jul 12, 2004, in forum: HTML
    Replies:
    2
    Views:
    1,270
    Toby Inkster
    Jul 12, 2004
  2. Luigi Donatello Asero

    Checking links and robots.

    Luigi Donatello Asero, Aug 13, 2004, in forum: HTML
    Replies:
    21
    Views:
    1,003
    Sam Hughes
    Aug 14, 2004
  3. Luigi Donatello Asero

    Re: Checking links and robots.

    Luigi Donatello Asero, Aug 14, 2004, in forum: HTML
    Replies:
    4
    Views:
    371
    Luigi Donatello Asero
    Aug 14, 2004
  4. John Fitzsimons
    Replies:
    4
    Views:
    344
    John Fitzsimons
    May 19, 2008
  5. Joti
    Replies:
    6
    Views:
    133
    Ben Morrow
    Feb 22, 2004
Loading...

Share This Page