Browse Source

youhua

master
4670101279 2 years ago
parent
commit
d0dd6cc70f
  1. 5
      ruoyi-code/src/main/java/com/ruoyi/code/camera/scheduled/RtspScreenshotTask.java
  2. 15
      ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java

5
ruoyi-code/src/main/java/com/ruoyi/code/camera/scheduled/RtspScreenshotTask.java

@ -7,6 +7,7 @@ import com.ruoyi.code.camera.domain.CameraBrand;
import com.ruoyi.code.camera.service.ICameraBrandService; import com.ruoyi.code.camera.service.ICameraBrandService;
import com.ruoyi.code.camera.service.ICameraService; import com.ruoyi.code.camera.service.ICameraService;
import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.http.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
@ -43,7 +44,9 @@ public class RtspScreenshotTask {
file.mkdirs(); file.mkdirs();
} }
String ffmpeg = "ffmpeg -i \"rtsp://"+camera.getUsername()+":"+camera.getPassword()+"@"+camera.getIp()+cameraBrand.getRtsp()+"\" -y -f image2 -t 0.001 \""+fileName+currentTime+"\""; String ffmpeg = "ffmpeg -i \"rtsp://"+camera.getUsername()+":"+camera.getPassword()+"@"+camera.getIp()+cameraBrand.getRtsp()+"\" -y -f image2 -t 0.001 \""+fileName+currentTime+"\"";
RuntimeUtil.execForStr(ffmpeg); if(HttpUtils.checkPing(camera.getIp())){
RuntimeUtil.execForStr(ffmpeg);
}
} }
} }
} }

15
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java

@ -11,12 +11,16 @@ import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import cn.hutool.core.util.RuntimeUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.Constants;
@ -271,4 +275,15 @@ public class HttpUtils
return true; return true;
} }
} }
private final static Pattern PATTERN= Pattern.compile("(\\d+ms)(\\s+)(TTL=\\d+)", Pattern.CASE_INSENSITIVE);
public static boolean checkPing(String ip) {
//若line含有=18ms TTL=16字样,说明已经ping通,返回true,否則返回false.
String result = RuntimeUtil.execForStr("ping " + ip + " -n 2 -w 2000");
Matcher matcher = PATTERN.matcher(result);
if (matcher.find()) {
return true;
}
return false;
}
} }
Loading…
Cancel
Save