import java.io.*; import java.net.*; import java.util.*; import org.apache.commons.mail.*; /** * Check if a sites in the properties file are still up. */ public class SiteCheck { public static void main(String[] args) throws Exception { Properties props=new Properties(); props.load(new FileInputStream(args[0])); String mailServer=props.getProperty("mail_server"); String to=props.getProperty("to"); String from=props.getProperty("from"); String subject=props.getProperty("subject"); String message="Website status:\n\n"; for(int i=0; ; i++) { String host=props.getProperty("site_"+i); if(host==null) break; try { URL url=new URL("http://"+host); URLConnection con=url.openConnection(); InputStream in=con.getInputStream(); byte[] buffer=new byte[2048]; while(in.read(buffer)!=-1); in.close(); message+=" -"+host+": ok\n"; } catch(Exception e) { message+=" -"+host+": "+e.getMessage()+"\n"; } } SimpleEmail email=new SimpleEmail(); email.setHostName(mailServer); email.addTo(to); email.setFrom(from); email.setSubject(subject); email.setMsg(message); email.send(); } }