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}} 短信