From 3b5a37c270e5b6649b9a168ee753c2b3353a257a Mon Sep 17 00:00:00 2001
From: zouyaoji <370681295@qq.com>
Date: 星期六, 06 八月 2022 11:27:02 +0800
Subject: [PATCH] 前端显示媒体服务器配置时报错修复
---
src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java | 24 +++++++++++++++++++++++-
1 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
index 85f4684..c24e0ca 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
@@ -6,6 +6,10 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.regex.Pattern;
+
@Configuration("mediaConfig")
public class MediaConfig{
@@ -161,7 +165,18 @@
if (StringUtils.isEmpty(sdpIp)){
return ip;
}else {
- return sdpIp;
+ if (isValidIPAddress(sdpIp)) {
+ return sdpIp;
+ }else {
+ // 鎸夌収鍩熷悕瑙f瀽
+ String hostAddress = null;
+ try {
+ hostAddress = InetAddress.getByName(sdpIp).getHostAddress();
+ } catch (UnknownHostException e) {
+ throw new RuntimeException(e);
+ }
+ return hostAddress;
+ }
}
}
@@ -211,4 +226,11 @@
return mediaServerItem;
}
+ private boolean isValidIPAddress(String ipAddress) {
+ if ((ipAddress != null) && (!ipAddress.isEmpty())) {
+ return Pattern.matches("^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$", ipAddress);
+ }
+ return false;
+ }
+
}
--
Gitblit v1.8.0