From 866f90831fb7242a68a8326b9a05c7e90fc43c56 Mon Sep 17 00:00:00 2001
From: pppscn <35696959@qq.com>
Date: Sun, 7 Apr 2024 18:17:19 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A`{{IP=5FLIST}}`?=
=?UTF-8?q?=E5=8F=98=E9=87=8F=E6=A0=87=E7=AD=BE=E7=94=A8=E4=BA=8E=E8=8E=B7?=
=?UTF-8?q?=E5=8F=96`=E6=9C=AC=E6=9C=BA=E6=89=80=E6=9C=89IP=E5=9C=B0?=
=?UTF-8?q?=E5=9D=80=E5=88=97=E8=A1=A8`=EF=BC=88=E6=8E=92=E9=99=A4?=
=?UTF-8?q?=E7=8E=AF=E5=9B=9E=E5=9C=B0=E5=9D=80=EF=BC=89=20#I9CVLZ?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt | 1 +
.../java/com/idormy/sms/forwarder/utils/Constants.kt | 1 +
.../com/idormy/sms/forwarder/utils/task/TaskUtils.kt | 4 ++++
.../com/idormy/sms/forwarder/workers/NetworkWorker.kt | 9 +++++++++
app/src/main/res/values/strings.xml | 1 +
5 files changed, 16 insertions(+)
diff --git a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt
index 9f9297ff..c45b751b 100644
--- a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt
+++ b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt
@@ -105,6 +105,7 @@ data class MsgInfo(
)
.replaceTag(getString(R.string.tag_ipv4), TaskUtils.ipv4, needJson)
.replaceTag(getString(R.string.tag_ipv6), TaskUtils.ipv6, needJson)
+ .replaceTag(getString(R.string.tag_ip_list), TaskUtils.ipList, needJson)
.replaceTag(getString(R.string.tag_battery_pct), "%.0f%%".format(TaskUtils.batteryPct), needJson)
.replaceTag(getString(R.string.tag_battery_status), BatteryUtils.getStatus(TaskUtils.batteryStatus), needJson)
.replaceTag(getString(R.string.tag_battery_plugged), BatteryUtils.getPlugged(TaskUtils.batteryPlugged), needJson)
diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/Constants.kt b/app/src/main/java/com/idormy/sms/forwarder/utils/Constants.kt
index 91e31036..bcfde57b 100644
--- a/app/src/main/java/com/idormy/sms/forwarder/utils/Constants.kt
+++ b/app/src/main/java/com/idormy/sms/forwarder/utils/Constants.kt
@@ -278,6 +278,7 @@ const val SP_DATA_SIM_SLOT = "data_sim_slot"
const val SP_WIFI_SSID = "wifi_ssid"
const val SP_IPV4 = "ipv4"
const val SP_IPV6 = "ipv6"
+const val SP_IP_LIST = "ip_list"
const val SP_SIM_STATE = "sim_state"
const val SP_LOCATION_INFO_OLD = "location_info_old"
const val SP_LOCATION_INFO_NEW = "location_info_new"
diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/task/TaskUtils.kt b/app/src/main/java/com/idormy/sms/forwarder/utils/task/TaskUtils.kt
index 5aefb22a..5ea8f513 100644
--- a/app/src/main/java/com/idormy/sms/forwarder/utils/task/TaskUtils.kt
+++ b/app/src/main/java/com/idormy/sms/forwarder/utils/task/TaskUtils.kt
@@ -15,6 +15,7 @@ import com.idormy.sms.forwarder.utils.SP_DATA_SIM_SLOT
import com.idormy.sms.forwarder.utils.SP_DISCOVERED_DEVICES
import com.idormy.sms.forwarder.utils.SP_IPV4
import com.idormy.sms.forwarder.utils.SP_IPV6
+import com.idormy.sms.forwarder.utils.SP_IP_LIST
import com.idormy.sms.forwarder.utils.SP_LOCATION_INFO_NEW
import com.idormy.sms.forwarder.utils.SP_LOCATION_INFO_OLD
import com.idormy.sms.forwarder.utils.SP_LOCK_SCREEN_ACTION
@@ -143,6 +144,9 @@ class TaskUtils private constructor() {
//IPv6地址
var ipv6: String by SharedPreference(SP_IPV6, "")
+ //IP地址列表
+ var ipList: String by SharedPreference(SP_IP_LIST, "")
+
//SIM卡状态:0-未知状态,1-卡被移除,5-卡已准备就绪
var simState: Int by SharedPreference(SP_SIM_STATE, 0)
diff --git a/app/src/main/java/com/idormy/sms/forwarder/workers/NetworkWorker.kt b/app/src/main/java/com/idormy/sms/forwarder/workers/NetworkWorker.kt
index 7ad838d0..6926ce28 100644
--- a/app/src/main/java/com/idormy/sms/forwarder/workers/NetworkWorker.kt
+++ b/app/src/main/java/com/idormy/sms/forwarder/workers/NetworkWorker.kt
@@ -14,6 +14,7 @@ import com.idormy.sms.forwarder.core.Core
import com.idormy.sms.forwarder.entity.MsgInfo
import com.idormy.sms.forwarder.entity.TaskSetting
import com.idormy.sms.forwarder.entity.condition.NetworkSetting
+import com.idormy.sms.forwarder.utils.CommonUtils
import com.idormy.sms.forwarder.utils.Log
import com.idormy.sms.forwarder.utils.PhoneUtils
import com.idormy.sms.forwarder.utils.TaskWorker
@@ -40,6 +41,9 @@ class NetworkWorker(context: Context, params: WorkerParameters) : CoroutineWorke
val ipv6 = getPublicIP(true)
TaskUtils.ipv6 = if (ipv6Pattern.matches(ipv6)) ipv6 else ""
Log.d(TAG, "ipv4 = $ipv4, ipv6 = $ipv6")
+ //获取所有IP地址
+ val ipList = CommonUtils.getIPAddresses().filter { !isLocalAddress(it) }
+ TaskUtils.ipList = if (ipList.isNotEmpty()) ipList.joinToString("\n") else ""
val conditionType = inputData.getInt(TaskWorker.CONDITION_TYPE, -1)
val taskList = Core.task.getByType(conditionType)
@@ -165,4 +169,9 @@ class NetworkWorker(context: Context, params: WorkerParameters) : CoroutineWorke
}
}
+ //检查IP地址是否为本地地址
+ private fun isLocalAddress(ip: String): Boolean {
+ return ip == "127.0.0.1" || ip == "::1" || ip.startsWith("fe80:") || ip.startsWith("fec0:")
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c9e6d42b..b9f5fc2b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -24,6 +24,7 @@
{{UID}}
{{IPV4}}
{{IPV6}}
+ {{IP_LIST}}
{{NET_TYPE}}
短信