1.代码
**
* @ClassName XMLGenerator
* @Description TODO
* @Author duckweed
* @Date 2023/7/20 9:58
* @Version 1.0
*/
public class XMLGenerator {
/**
* 标识
*/
private static List displayNames = Arrays.asList(
"-149",
"-141",
"-191",
"-241",
"-102",
"-59",
"-234",
"-82",
"-199",
"-213",
"-71",
"-50",
"-221",
"-98",
"-45",
"-49",
"-33",
"-27",
"-42",
"-29",
"-14",
"-17",
"-21",
"-23",
"-22",
"-34",
"-38",
"-37",
"-5",
"-12",
"-46",
"-36",
"-32",
"-7",
"-41",
"-15",
"-18",
"-4",
"-26",
"-20",
"-16",
"-11",
"-24",
"-28",
"-10",
"-9",
"-19",
"-6"
);
/**
* 服务ip
*/
private static List ipAddresses = Arrays.asList("255.117.4.119",
"255.117.3.141",
"255.117.3.211",
"255.117.2.227",
"255.117.3.195",
"255.117.3.4",
"255.117.1.204",
"255.117.2.6",
"255.117.0.214",
"255.117.1.154",
"255.117.3.19",
"255.117.3.66",
"255.117.1.108",
"255.117.0.245",
"255.117.0.28",
"255.117.0.146",
"255.117.0.70",
"255.117.0.33",
"255.117.0.139",
"255.117.0.124",
"255.117.0.45",
"255.117.0.44",
"255.117.0.30",
"255.117.0.34",
"255.117.0.18",
"255.117.0.143",
"255.117.0.25",
"255.117.0.128",
"255.117.0.101",
"255.117.0.24",
"255.117.0.58",
"255.117.0.135",
"255.117.0.16",
"255.117.0.31",
"255.117.0.22",
"255.117.0.23",
"255.117.0.26",
"255.117.0.21",
"255.117.0.12",
"255.117.0.27",
"255.117.0.110",
"255.117.0.115",
"255.117.0.105",
"255.117.0.107",
"255.117.0.102",
"255.117.0.100",
"255.117.0.104",
"255.117.0.121");
public static void main(String[] args) {
generateXML(displayNames,ipAddresses,ipAddresses);
}
/**
* 生成xml 文件
* @param displayNames 标识地址
* @param serverNames
* @param ipAddresses ip 地址
*/
public static void generateXML(List displayNames, List serverNames, List ipAddresses) {
try {
FileWriter writer = new FileWriter("servers.xml");
writer.write("\n");
writer.write("\n");
for (int i = 0; i < ipAddresses.size(); i++) {
writer.write("\t\n");
writer.write("\t\t\n");
writer.write("\t\t\tDefault Settings \n");
writer.write("\t\t\t" + ipAddresses.get(i) + displayNames.get(i) + " \n");
writer.write("\t\t\t{" + generateUID() + "} \n");
writer.write("\t\t\t" + ipAddresses.get(i) + " \n");
writer.write("\t\t\t4 \n");
writer.write("\t\t\t22 \n");
writer.write("\t\t\t \n");
writer.write("\t\t\t \n");
writer.write("\t\t\t0 \n");
writer.write("\t\t\t" + ipAddresses.get(i) + " -ssh -P 22 \n");
writer.write("\t\t\t0 \n");
writer.write("\t\t \n");
writer.write("\t \n");
}
writer.write(" ");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private static String generateUID() {
// Generate a unique identifier here
return UuidUtils.generateUuid().toUpperCase();
}
}
2.生成的文件
3.导入