This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

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

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
t
tintin
Voice
Posts: 5
Joined: Thu Feb 07, 2013 3:25 am

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

Post by tintin »

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
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

The final version would be

Code: Select all

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: Select all

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
Post Reply