mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2007
Posts: 139
S
Solo1 Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2007
Posts: 139
greetings

What is the best way to check if a website is online and return an error if it is not?

Thanks

Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
I just wrote up a quick script, Just add it to the remotes section of mIRC scripts editor.

Code:
alias checkwebsite {
  if (!$1) {
    echo -at You need to specify a website!!!
  }
  else {
    var %sn checkwebsite. $+ $md5($ticks $+ $r(1111,9999))
    sockopen %sn $1 $iif($2,$ifmatch,80)
    sockmark %sn $1 $iif($2,$ifmatch,80)
  }
}

on 1:sockopen:checkwebsite.*:{
  if ($sockerr) {
    var %cw.msg There was an error connecting to:
  }
  else {
    var %cw.msg Successfully connected to:
  }
  echo -at * %cw.msg $replace($sock($sockname).mark,$chr(32),$+($chr(32),on port,$chr(32))) $iif($sockerr,$+($chr(40),$sock($sockname).wsmsg,$chr(41)))
  if ($sock($sockname)) {
    sockclose $ifmatch
  }
}


Usage: /checkwebsite <URL/IP> [PORT]

So to check hotmail website, type "/checkwebsite hotmail.com"
But if you need to check hotmail secure, then try "/checkwebsite hotmail.com 443"
or to check an IRC server, try /checkwebsite <servername> 6667

I think you should get it!
Hope this helps.

Last edited by The_JD; 13/02/08 02:44 PM.

[02:16] * Titanic has quit IRC (Excess Flood)
Joined: Mar 2007
Posts: 139
S
Solo1 Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2007
Posts: 139
thanks a million

Joined: Jan 2004
Posts: 509
L
Fjord artisan
Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Couldn't you also /dns it, and if no response, then, it's down?

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
No. DNS records are stored on a nameserver, which is very rarely the same machine that hosts the actual website. Even if it was, the fact that DNS is responding is no guarantee that a specific webpage is also running correctly.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Code:
alias http.status {
  .comopen xml msxml2.xmlhttp
  noop $com(xml,open,1,bstr,get,bstr,http:// $+ $1,bool,-1) 
  var %a = User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322) : $&
    Host: $1 :Accept-Language:en-us:Accept-Encoding:gzip, deflate:UA-CPU:x86:Proxy-Connection:Keep-Alive: $&
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, */* $&
    ,%i = 1
  tokenize 58 %a
  while ($(,$ $+ %i)) {
    noop $com(xml,setRequestHeader,3,bstr,$v1,bstr,$gettok(%a,$calc(%i +1),32))
    inc %i 2
  }
  noop $com(xml,send,1) $com(xml,status,2) 
  var %x $com(xml).result
  .comclose xml
  return %x
  :error
  if ($comerr) echo -geca info * $!http.status : $error $com(xml).errorText 
  reseterror
  return 0
}


Returns 200 if website loaded OK (HTTP Value for OK) and otherwise returns the HTTP Code (i.e 404 and 500) or the WinSock Error Code.

usage:
Code:
  if ($http.status(www.mirc.com) == 200) sockopen ...
  else echo -a cannot open mirc.com website is down!


$maybe
Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
Originally Posted By: Solo1
thanks a million


No probs, Glad to help smile


@MPDreamz: Using HTTP status codes isnt good for detecting if a website is online.

* If I have forbidden a user from viewing /index.php without logging in first, I would return 403 forbidden.
* If the site is SSL, Plain text of the status codes
wouldnt be returned (allthough the object may allow it).
* Because a page is missing (404) dosnt mean the whole website is down.

Im sure you get the point.


[02:16] * Titanic has quit IRC (Excess Flood)
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Thats because i assumed he wanted to check if he could connect properly. You could check for WinSock Errors directly by checking
Code:
if ($http.status(www.mirc.com) > 600) echo -a site down or does not  exist.

Your right about username and password though, so i thought id include it smile
Code:
alias http.status {
  var %p http://,%u $2,%w $3,%a Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322), %x
  if ($prop) %p = https://
  .comopen xml msxml2.xmlhttp
  if ($0 < 2) echo -a $com(xml,open,1,bstr,head,bstr,%p $+ $1,bool,-1) 
  else noop $com(xml,open,1,bstr,head,bstr,%p $+ $1,bool,-1,bstr,%u,bstr,%w) 
  noop $com(xml,setRequestHeader,3,bstr,User-Agent,bstr,%a) $com(xml,send,1) $com(xml,status,2) 
  %x = $com(xml).result
  .comclose xml
  return %x
  :error
  echo -geca info * $!http.status : $error $com(xml).errorText 
  if ($com(xml)) .comclose xml
  reseterror
  return s
}


usage: $http.status(URL[,username[,password]])[.secure]



$maybe

Link Copied to Clipboard