« March 2009 | Main | May 2009 »
With the help of some folks on the groovy-user mailing list, I wrote the following script to pull the server name header from an HTTP HEAD request. Mostly, I use this for verification purposes when setting ServerTokens to Prod on an apache server or when suppressing the tomcat server identity. The script uses Tom Nichols' HTTP Builder module for groovy. Running it is pretty straightforward as the script only takes one argument; enter the URL of the site you want to test. For example:
./checkServerType.groovy http://blogs.techstacks.com/
#!/usr/bin/env groovy
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.HEAD
import static groovyx.net.http.ContentType.TEXT
// create a new builder
def http = new HTTPBuilder( args[0] )
http.request( HEAD, TEXT ) {req ->
response.success = { resp ->
println " ${resp.getFirstHeader('Server')} "
}
response.failure = { resp ->
println "Server Response: ${resp.statusLine}"
}
}
I've been playing with Groovy lately and using it to play with some web services. They will only work if you have the groovy xmlrpc library in your $GROOVY_LIB. The following scripts are basic ping scripts for blog directories Technorati, IceRocket, and Blo.gs. Plug in your blog's title and blog's URL and ping away!
#!/usr/bin/env groovy
import groovy.net.xmlrpc.*
def server = new XMLRPCServerProxy("http://rpc.technorati.com/rpc/ping")
def result = server.weblogUpdates.ping("BLOG TITLE" , "BLOG URL")
if (result != null)
println "Thanks for the ping!"
#!/usr/bin/env groovy
import groovy.net.xmlrpc.*
def server = new XMLRPCServerProxy("http://rpc.icerocket.com:10080/")
def result = server.ping("BLOG TITLE" , "BLOG URL")
if (result != null)
println "Thanks for the ping!"
#!/usr/bin/env groovy
import groovy.net.xmlrpc.*
def server = new XMLRPCServerProxy("http://ping.blo.gs/")
def result = server.weblogUpdates.extendedPing("BLOG TITLE" , "BLOG URL" , "FEED URL")
if (result != null)
println "Thanks for the ping!"