Skip to content

Commit

Permalink
Enhance Router Connection validation
Browse files Browse the repository at this point in the history
  • Loading branch information
krxkli committed Sep 4, 2024
1 parent 558a2a0 commit 712375a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId = "com.krxkli.scut_router"
minSdk = 24
targetSdk = 34
versionCode = 4
versionName = "1.1.2"
versionCode = 5
versionName = "1.1.3"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Binary file modified Android/app/release/app-release.apk
Binary file not shown.
Binary file modified Android/app/release/baselineProfiles/0/app-release.dm
Binary file not shown.
Binary file modified Android/app/release/baselineProfiles/1/app-release.dm
Binary file not shown.
4 changes: 2 additions & 2 deletions Android/app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 4,
"versionName": "1.1.2",
"versionCode": 5,
"versionName": "1.1.3",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ class MainActivity : AppCompatActivity() {
val context: Context = this
val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
val wifiInfo = wifiManager.connectionInfo
val dhcpInfo = wifiManager.dhcpInfo
val ipAddr = wifiInfo.ipAddress
val gateway = dhcpInfo.gateway

val ipStr = Formatter.formatIpAddress(ipAddr)
val gatewayStr = Formatter.formatIpAddress(gateway)
println("IP 地址: $ipStr")
println("网关地址: ${gatewayStr}")

val interfaces = NetworkInterface.getNetworkInterfaces()
while (interfaces.hasMoreElements()) {
Expand All @@ -137,7 +141,9 @@ class MainActivity : AppCompatActivity() {

println("IP 子网: ${subNet.networkAddress}")

if (subNet.networkAddress == this.getString(R.string.default_router_conn)) {
if (subNet.networkAddress == this.getString(R.string.default_router_conn) && gatewayStr == getString(
R.string.default_router_gateway
)) {
return true
} else {
return false
Expand Down
1 change: 1 addition & 0 deletions Android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
<string name="loadCore">Loading Core</string>
<string name="core_loaded_successfully">Core Loaded successfully</string>
<string name="wlanIfaName" translatable="false">wlan0</string>
<string name="default_router_gateway" translatable="false">192.168.0.101</string>
</resources>

0 comments on commit 712375a

Please sign in to comment.