- // Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
- // Jad home page: http://kpdus.tripod.com/jad.html
- // Decompiler options: packimports(3) fieldsfirst ansi space
- // Source File Name: Monitor.java
- package com.gsteel;
- import java.awt.Toolkit;
- import java.io.*;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.*;
- public class Monitor
- {
- static int timeOut = 3000;
- private static final String path = "com/gsteel/settings.properties";
- private static PrintWriter log;
- private static String ipstest[];
- private static String mobilestest[];
- private static Map ipresult = new HashMap();
- public Monitor()
- {
- }
- public static void main(String args[])
- {
- Properties dbProps = new Properties();
- String logFile = "C://ServerMonitor.log";
- try
- {
- log = new PrintWriter(new FileWriter(logFile, true), true);
- }
- catch (IOException e)
- {
- System.err.println((new StringBuilder("沒法打開日誌文件: ")).append(logFile).toString());
- log = new PrintWriter(System.err);
- }
- java.io.InputStream is = com/gsteel/Monitor.getClassLoader().getResourceAsStream("com/gsteel/settings.properties");
- try
- {
- dbProps.load(is);
- }
- catch (Exception e)
- {
- System.err.println("不能讀取屬性文件. 請確保settings.properties在CLASSPATH指定的路徑中");
- log("不能讀取屬性文件請確保settings.properties在CLASSPATH指定的路徑中");
- return;
- }
- String ips = dbProps.getProperty("ip", "222.73.38.236");
- String mobiles = dbProps.getProperty("mobile", "18978819181");
- ipsipstest = ips.split(";");
- mobilesmobilestest = mobiles.split(";");
- try
- {
- do
- {
- for (int i = 0; i < ipstest.length; i++)
- {
- boolean status = pingServer(ipstest[i], timeOut);
- if (!status)
- {
- Thread.sleep(800L);
- boolean restatus = pingServer(ipstest[i], timeOut);
- if (!restatus)
- {
- Thread.sleep(800L);
- if (!pingServer(ipstest[i], timeOut))
- {
- alert();
- sendMessage(mobilestest, (new StringBuilder(String.valueOf(ipstest[i]))).append("運行異常,請及時處理").toString());
- log((new StringBuilder(String.valueOf(ipstest[i]))).append("異常,短信已發送!").toString());
- }
- }
- } else
- {
- log((new StringBuilder(String.valueOf(ipstest[i]))).append("運行正常!").toString());
- }
- Thread.sleep(3100L);
- }
- Thread.sleep(6000L);
- } while (true);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- }
- public static void init()
- {
- }
- public static boolean pingServer(String ip, int timeout)
- {
- Runtime r;
- String pingCommand;
- BufferedReader in = null;
- r = Runtime.getRuntime();
- pingCommand = (new StringBuilder("ping ")).append(ip).append(" -w ").append(timeout).toString();
- Process p;
- Object count;
- p = r.exec(pingCommand);
- if (p != null)
- break MISSING_BLOCK_LABEL_159;
- System.out.println((new StringBuilder(String.valueOf(ip))).append("運行異常!!! null").toString());
- count = ipresult.get(ip);
- if (count != null)
- break MISSING_BLOCK_LABEL_103;
- ipresult.put(ip, Integer.valueOf(1));
- return false;
- if (Integer.valueOf(count.toString()).intValue() < 2)
- break MISSING_BLOCK_LABEL_131;
- System.out.println(count.toString());
- return true;
- BufferedReader in;
- String line;
- try
- {
- ipresult.put(ip, Integer.valueOf(Integer.valueOf(count.toString()).intValue() + 1));
- }
- catch (Exception ex)
- {
- System.out.println((new StringBuilder(String.valueOf(ip))).append("運行異常!!!Exception").toString());
- return false;
- }
- return false;
- in = new BufferedReader(new InputStreamReader(p.getInputStream()));
- line = null;
- goto _L1
- _L4:
- if (!line.startsWith("Reply from")) goto _L1; else goto _L2
- _L2:
- System.out.println((new StringBuilder(String.valueOf(ip))).append("運行正常!!!").toString());
- ipresult.remove(ip);
- log((new StringBuilder(String.valueOf(ip))).append("運行正常!!!").toString());
- return true;
- _L1:
- if ((line = in.readLine()) != null) goto _L4; else goto _L3
- _L3:
- in.close();
- Object count = ipresult.get(ip);
- if (count == null)
- {
- ipresult.put(ip, Integer.valueOf(1));
- return false;
- }
- if (Integer.valueOf(count.toString()).intValue() >= 2)
- {
- return false;
- } else
- {
- ipresult.put(ip, Integer.valueOf(Integer.valueOf(count.toString()).intValue() + 1));
- return false;
- }
- }
- public static String sendMessage(String mobile[], String content)
- {
- String result = "";
- String mobiles = "";
- try
- {
- for (int i = 0; i < mobile.length - 1; i++)
- mobiles = (new StringBuilder(String.valueOf(mobiles))).append(mobile[i]).append(",").toString();
- mobiles = (new StringBuilder(String.valueOf(mobiles))).append(mobile[mobile.length - 1]).toString();
- String urlName = (new StringBuilder("http://211.157.113.148:8060/z_send.aspx?sn=SDK-WSS-010-01070&pwd=995162&mobile=")).append(mobiles).append("&").append("content=").append(content).toString();
- System.out.println(urlName);
- URL U = new URL(urlName);
- URLConnection connection = U.openConnection();
- connection.connect();
- BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String line;
- while ((line = in.readLine()) != null)
- result = (new StringBuilder(String.valueOf(result))).append(line).append("\n").toString();
- in.close();
- }
- catch (Exception e)
- {
- System.out.println((new StringBuilder("沒有結果!")).append(e).toString());
- }
- return result;
- }
- private static void log(String msg)
- {
- log.println((new StringBuilder()).append(new Date()).append(": ").append(msg).toString());
- }
- private static void log(Throwable e, String msg)
- {
- log.println((new StringBuilder()).append(new Date()).append(": ").append(msg).toString());
- e.printStackTrace(log);
- }
- private static void alert()
- {
- int count = 0;
- do
- {
- Toolkit.getDefaultToolkit().beep();
- if (count <= 40)
- {
- count++;
- try
- {
- Thread.sleep(500L);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- } else
- {
- return;
- }
- } while (true);
- }
- }
settings.propertieshtml
- mobile=18978819181;18777156276
- ip=222.73.38.215;222.73.38.223;222.73.38.235;222.73.38.236;222.73.38.237