From d31f2155237aa65cee1cb6ce1d39c48191663226 Mon Sep 17 00:00:00 2001 From: panlili2024 <14743743+panlili2024@user.noreply.gitee.com> Date: 星期五, 21 二月 2025 18:02:41 +0800 Subject: [PATCH] 新增source屏接口及房间及绑定关系接口 --- HDLSDK/app/src/main/java/com/hdl/hdlsdk/EthernetUtils.java | 63 +++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-) diff --git a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/EthernetUtils.java b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/EthernetUtils.java new file mode 100644 index 0000000..fdb9896 --- /dev/null +++ b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/EthernetUtils.java @@ -0,0 +1,63 @@ +package com.hdl.hdlsdk; + +import android.text.TextUtils; +import android.util.Log; + +import java.util.regex.Pattern; + +public class EthernetUtils { + + public boolean checkIPValue(String ipAddr, String gateway, String netMask, String dns1, String dns2) { + boolean enable = false; + Pattern pattern = Pattern.compile("(^((\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])$)|^(\\d|[1-2]\\d|3[0-2])$"); /*check subnet mask*/ + if (isValidIpAddress(ipAddr) && isValidIpAddress(gateway) + && isValidIpAddress(dns1) && (pattern.matcher(netMask).matches())) { + if (TextUtils.isEmpty(dns2)) { // 涓虹┖鍙互涓嶈�冭檻 + enable = true; + } else { + if (isValidIpAddress(dns2)) { + enable = true; + } else { + enable = false; + } + } + } else { + enable = false; + } + return enable; + } + + + private boolean isValidIpAddress(String value) { + int start = 0; + int end = value.indexOf('.'); + int numBlocks = 0; + + while (start < value.length()) { + + if (-1 == end) { + end = value.length(); + } + + try { + int block = Integer.parseInt(value.substring(start, end)); + if ((block > 255) || (block < 0)) { + Log.w("EthernetIP", + "isValidIpAddress() : invalid 'block', block = " + + block); + return false; + } + } catch (NumberFormatException e) { + Log.w("EthernetIP", "isValidIpAddress() : e = " + e); + return false; + } + + numBlocks++; + + start = end + 1; + end = value.indexOf('.', start); + } + return numBlocks == 4; + } + +} -- Gitblit v1.8.0