package lct.conference.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; public class Test3 {
public static void main(String[] args){
String[] cmdStr = { "cmd", "/C", "wmic /node:\"192.168.0.34\" /user:\"administrator\" /password:\"12345\" service get /value" };
List<Map<String, Object>> list = null;
try {
list = getAllResult(cmdStr, 25);
System.out.println(list.size());
JSONArray jr = JSONArray.fromObject(list);
JSONObject jo = new JSONObject();
for(int i=0;i<list.size();i++){
jo.clear();
jo=(JSONObject) jr.get(i);
if("Apache Tomcat".equals(jo.get("Caption"))){
String ifStarted = jo.get("Started").toString();
System.out.println( "Apache Tomcat服务"+ifStarted);
}else if("MySQL".equals(jo.get("Caption"))){
String ifStarted = jo.get("Started").toString();
System.out.println( "MySQL服务"+ifStarted);
}else if("PCMS Service".equals(jo.get("Caption"))){
String ifStarted = jo.get("Started").toString();
System.out.println( "PCMS Service服务"+ifStarted);
}else if("PCMS Watch Service".equals(jo.get("Caption"))){
String ifStarted = jo.get("Started").toString();
System.out.println( "PCMS Watch Service服务"+ifStarted);
}
}
System.out.println(list);
} catch (IOException e) {
e.printStackTrace();
System.out.println( "获取所有服务信息失败!");
}
}
private static List<Map<String, Object>> getAllResult(String[] cmdStr, int flag) throws IOException {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Integer index = 1;
Process p = null;
String str = null;
String[] arrStr = new String[2];
Map<String, Object> map = new HashMap<String, Object>();
InputStreamReader isr = null;
BufferedReader br = null;
try {
p = Runtime.getRuntime().exec(cmdStr);
isr = new InputStreamReader(p.getInputStream(),"GBK");
br = new BufferedReader(isr);
while ((str = br.readLine()) != null) {
if (str!=null && !"".equals(str)) {
if (index % flag == 0) {
list.add(map);
map = new HashMap<String, Object>();
}
arrStr = str.split("=");
str = str.endsWith("=") ? "" : arrStr[1];
map.put(arrStr[0], str);
index++;
}
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("获取进程的所有信息失败!");
throw e;
} catch (Exception e) {
e.printStackTrace();
System.out.println("获取执行结果失败!");
} finally {
try {
if (br != null) {
}
br.close();
if (isr != null) {
isr.close();
}
} catch (IOException e) {
e.printStackTrace();
}
if (p != null) {
p.destroy();
}
}
return list;
}
}

java获取远程服务器应用程序服务状态的更多相关文章

  1. JAVA本地远程连接linux程序监控状态

    环境:  1.本地window 2.程序部署在centos   一,启动访问权限安全守护程序 新建文件:jstatd.all.policy ,注意路径 grant codebase "$JA ...

  2. 使用nodejs和Java访问远程服务器的服务

    既然这篇文章用的是nodejs和Java访问远程服务器的服务,那么咱们先用另一门编程语言,SAP的ABAP(我日常工作使用得最多的编程语言)来开发一个服务吧. 这是我用ABAP编程语言实现服务的类:Z ...

  3. Windows系统中使用WMI获取远程服务器的信息

    使用WMI获取远程服务器的状态 我做的项目里边主要包含两个内容: (1)对发布在服务器上的服务(IIS服务.WCF服务)是否可以正常访问: (2)获取服务器上的部分指标:如CPU.内存.磁盘空间信息等 ...

  4. Java获取Web服务器文件

    Java获取Web服务器文件 如果获取的是服务器上某个目录下的有关文件,就相对比较容易,可以设定死绝对目录,但是如果不能设定死绝对目录,也不确定web服务器的安装目录,可以考虑如下两种方式: 方法一: ...

  5. 使用 xcode 8 构建版本 iTunes Connect 获取不到应用程序的状态

    今天在提交 APP 审核版本的时候iTunes Connect 一直获取不到应用程序的状态,原因是,14号 xcode 8一出 直接升级使用 xcode 8 打包发布包,然后直接用 xcode8 构建 ...

  6. C# 获取当前服务器运行程序的根目录,获取当前运行程序物理路径

    C# 获取当前服务器运行程序的根目录,获取当前运行程序物理路径 string tmpRootDir = AppDomain.CurrentDomain.BaseDirectory;//获得当前服务器程 ...

  7. C# 获取当前服务器运行程序的根目录

    C# 获取当前服务器运行程序的根目录,获取当前运行程序物理路径 string tmpRootDir = AppDomain.CurrentDomain.BaseDirectory;//获得当前服务器程 ...

  8. java ssh远程服务器并执行多条shell命令

    java ssh远程服务器并执行多条命令 import java.io.BufferedReader; import java.io.IOException; import java.io.Input ...

  9. Java 程序检查远程服务器状态

    通常我们以命令的方式判断远程服务器是否正常运行有两种方式,ping 或 telnet 一个远程端口.假设我们要检查的远程服务器都是 Linux 系统. 从 JDK 1.5 以后, InetAddres ...

随机推荐

  1. wx存储数据到本地及本地获取

    官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.setStorageSync.html 存到本地就是存到手机的 ...

  2. 机器学习xgboost参数解释笔记

    首先xgboost有两种接口,xgboost自带API和Scikit-Learn的API,具体用法有细微的差别但不大. 在运行 XGBoost 之前, 我们必须设置三种类型的参数: (常规参数)gen ...

  3. BUG:WSL 的 ssh server 无法启动

    BUG 使用 sudo service ssh start 启动 ssh 服务,提示: * Restarting OpenBSD Secure Shell server sshd Could not ...

  4. 递推问题 hdu 2046 与1143的比对

    2046 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:   Input 输入数据由多行组成,每行 ...

  5. 刷新ip地址 windows linux系统

    linux:使用dhcp去更新ip与释放ip 释放ip: dhclient -r eth0 (释放eth0的ip) 更新ip : dhclient eth0 (针对eth0,请求新的ip) windo ...

  6. Self寄宿

    static void Main(string[] args) { //Assembly.Load("WebApplication1, Version=1.0.0.0, Culture=ne ...

  7. kvm第二章--虚拟机管理

  8. dvaJS Model之间的调用

    const Model: ModelType = { namespace: 'namesps', state: { data: {} }, effects: { *fetch({ payload, c ...

  9. 监听iframe加载完成

    用 @load="loading" 在Vue里面写了一个界面,有一个iframe标签, iframe加载其他网站, <iframe @load="loading&q ...

  10. 30分钟用Restful ABAP Programming模型开发一个支持增删改查的Fiori应用

    2016年时,Jerry曾经写过一系列关于SAP Fiori Smart Template(现在更名为Fiori Elements了)的博客,介绍了所谓的MDD开发方法论 - Metadata Dri ...