目录
一、软件功能与截图
做一款面向网络运维人员的IP通断状态检测小软件,核心是通过运行Ping命令拿到IP网络状态,目前有一个简陋UI界面,支持批量导入Excel格式的IP数据,然后自动检测网络通断。软件本体是jar包,可以通过exe4j工具打包为Windows PC机下运行的EXE程序,也可以运行到Linux操作系统。
该文档不定时更新。
未来打算支持功能点有:
- 将支持单个IP做网络通断测试,即每一个IP旁边放置一个按钮
- 将支持将IP检测结果表格导出为PDF或图片,方便分享数据
- 将支持自动不定时对IP地址做检测,动态更新检测结果
- 计划增加多线程,缩短响应时间
多Excel文档批量导入IP信息
1.文件支持选择多个Excel文档
2.Excel文件的表头要求
表头名字随便取,顺序必须与截图保持一致。
IP信息Ping结果列表展示
二、源码分享与设计
Maven-Pom依赖
<!-- POI Excel Jar-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
</dependency>
Excel数据导入-基于POI包
- 负责解析Excel数据为Java对象PingInfoInputDTO的方法类:MyExcelServiceImpl
public class MyExcelServiceImpl implements EasyExcelService {
@Override
public List<PingInfoInputDTO> readExcel(File file) {
try {
// HSSFWorkbook workBook = new HSSFWorkbook(new FileInputStream(new File(file.getAbsolutePath())));
HSSFWorkbook workBook = new HSSFWorkbook(new FileInputStream(file));
//页
int sheetNum = workBook.getNumberOfSheets();
DataFormatter cellDataFormatter = new DataFormatter();
List<PingInfoInputDTO> pingInfoList = new ArrayList<>(300);
for( int i=0; i<sheetNum; i++ ){
HSSFSheet sheetData = workBook.getSheetAt(i);
//行:每行数据对应一个对象
int lastRowNum = sheetData.getLastRowNum();
for( int j=1; j<lastRowNum ; j++){
//跳过首行表头,j=1
HSSFRow rowData = sheetData.getRow(j);
//单元格
short lastCellNum = rowData.getLastCellNum();
PingInfoInputDTO pingDTO = new PingInfoInputDTO();
int k = 0;
//IpNo数据编号
pingDTO.setIpNo(cellDataFormatter.formatCellValue(rowData.getCell(k++)));
//IP地址别名
pingDTO.setIpAliasName(cellDataFormatter.formatCellValue(rowData.getCell(k++)));
//IP地址
pingDTO.setIpAddress(cellDataFormatter.formatCellValue(rowData.getCell(k++)));
//Ping超时
pingDTO.setPingTimeout(cellDataFormatter.formatCellValue(rowData.getCell(k++)));
//最大Ping次数
pingDTO.setPingMaxCount(cellDataFormatter.formatCellValue(rowData.getCell(k++)));
pingInfoList.add(pingDTO);
}
}
workBook.close();
return pingInfoList;
} catch (FileNotFoundException e) {
e.printStackTrace()