egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Check if a website is up and change the topic to match

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
tintin
Voice


Joined: 07 Feb 2013
Posts: 5

PostPosted: Thu Feb 07, 2013 3:36 am    Post subject: Check if a website is up and change the topic to match Reply with quote

Iv searched google and the archive, maybe I missed something but either way I'm putting this request here. If you know of something let me know what to search for or where to look. I don't mind doing some more digging.

What I'm looking for is a script that checks if a configured website is up eg returning the html status code 200 this can just be from a trigger, and then update the topic to say the website is up or down or just poke fun of the person if the site not down on a check.

I'm not afraid of a little work but I'm no coder the best I can do is edit existing scripts.

Thanks for any help.

Tintin
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Fri Feb 08, 2013 8:19 am    Post subject: Reply with quote

The final version would be


Code:

bind TIME - * checkHostReachable

set temp(chan) "#channel"
set temp(url) "www.chanrank.com"

package require http

proc checkHostReachable {min hour day month year} {
   global temp

   if {[catch {
         set tok [http::geturl "http://$temp(url)"]
         http::cleanup $tok
         return 1
      } err]} {
      if {[string match -nocase "*host is unreachable*" $err]} {
         putserv "TOPIC $temp(chan) :Website is down"
      } else {
         putserv "TOPIC $temp(chan) :Website is UP"
      }
   }
}


yet i tested another version

Code:
bind time - * change:topic

set temp(chan) "#channel"
set temp(website) "www.website"

proc change:topic {min hour day month year} {
   global temp

   set website [http::config -useragent "Mozilla"]
   set website [http::geturl "http://$temp(website)" -timeout 50000]

   set updown [http::status $website]
   set err [http::error $website]

   http::cleanup $website

   switch -exact -- $updown {
      "ok" {
         putserv "TOPIC $temp(chan) :the website is UP"
      }
      "eof" {
         putserv "TOPIC $temp(chan) :the website is down"
      }
      error {
         putserv "TOPIC $temp(chan) :Website is $err"
      }
   }
}


yet at the second version i couldnt test the EOF part it only worked if the website was UP and running but i heard the second version is more likely to be as it shouldl

So use the first version
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber