PingHelper.java
2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.sitech.ismp.coll.link;
/**
* Created with IntelliJ IDEA.
* User: Administrator
* Date: 14-3-18
* Time: 上午11:33
* To change this template use File | Settings | File Templates.
*/
public class PingHelper {
/** 默认ping5次 */
public static final String DEFAULT_PING_TIMES = "5";
/**
* 根据不同的系统获得不同的ping命令
* @param times ping次数
* @return
*/
public static String getPingTemplet(String times){
String command = null;
String osName = System.getProperty("os.name").toUpperCase();
if (osName.indexOf("SUN") > 0) {
command = LinkCollConst.PING_SUN;
} else if (osName.indexOf("HP") > 0) {
command = LinkCollConst.PING_HP;
} else {
command = LinkCollConst.PING_LINUX;
}
return command.replace("#PING_COUNT#", times);
}
/**
* 根据不同的系统获得不同的ping命令
* @return
*/
public static String getPingTemplet(){
return getPingTemplet(DEFAULT_PING_TIMES);
}
public static String getSeq(Hop nextHop) {
return LinkCollConst.ECHO_STR_TO_RESFILE
.replace("#STR_CONTENT#", "SEQ=" + nextHop.getSeq())
.replace("#LINK_ID#", nextHop.getLinkId());
}
public static String getDevId(Hop nextHop) {
return LinkCollConst.ECHO_STR_TO_RESFILE
.replace("#STR_CONTENT#", "DEVICE_ID=" + nextHop.getDevId())
.replace("#LINK_ID#", nextHop.getLinkId());
}
public static Object getIpAddr(Hop nextHop) {
return PingHelper.getPingTemplet()
.replace("#IP_ADDR#", nextHop.getIpAddr())
.replace("#LINK_ID#", nextHop.getLinkId());
}
public static Object getSplitLine(Hop nextHop) {
return LinkCollConst.ECHO_STR_TO_RESFILE
.replace("#STR_CONTENT#", LinkCollConst.SPLIT_LINE)
.replace("#LINK_ID#", nextHop.getLinkId());
}
public static Object getShellHead() {
return LinkCollConst.SH_TOP;
}
public static Object getShellFoot(String fileName) {
return LinkCollConst.MV_RESULT
.replace("#RESULT_TEMP_PATH#", LinkCollConst.RESULT_TEMP_PATH + "/" + fileName)
.replace("#RESULT_PATH#", LinkCollConst.RESULT_PATH);
}
}