@Scheduled(cron = "0/10 * * * * ?")
public void gatewayConnect(){
boolean linux = System.getProperty("os.name").toLowerCase().contains("linux");
boolean windows = System.getProperty("os.name").toLowerCase().contains("windows");
Runtime runtime = Runtime.getRuntime();
Process process = null;
try {
if(linux){
log.info("linux:{}",linux);
process = runtime.exec("ping -c 1 " + Constant.GATEWAY_IP);
}
if(windows){
log.info("windows:{}",windows);
process = runtime.exec("ping -n 1 " + Constant.GATEWAY_IP);
}
log.info("process:{}", JSONObject.toJSON(process));
Locale locale = Locale.getDefault();
log.info("language:"+locale.getLanguage());
log.info("country:"+locale.getCountry());
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is, locale.getLanguage().equals("zh")?"gbk":"utf-8");
BufferedReader br = new BufferedReader(isr);
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
}
is.close();
isr.close();
br.close();
log.info("ping ip rcv:" + sb.toString());
if (null != sb && !sb.toString().equals("")) {
String logString = "";
if (sb.toString().indexOf("TTL") > 0||sb.toString().indexOf("ttl")>0) {
log.info("connect is true");
} else {
log.info("connect is false");
}
}
}catch (Exception e){
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)