I'm trying to find the ip address of the wifi router my phone is currently connected to. I have tried the code below. It always returns the address of the phone I'm using now and not the router.
B4X:
Sub Process_Globals
Dim Server As ServerSocket
Dim router As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
Log("In FindWIFIusers")
'Server.Initialize("5100","Server")
router = Server.GetMyWifiIP
Server.close
Log("Router = " & router)
Activity.Finish
End Sub
in most cases router IP is the same as the phone IP but the last value is 1 ex. 192.168.1.1. So just get your phone wifi IP and change the last value to 1.
in most cases router IP is the same as the phone IP but the last value is 1 ex. 192.168.1.1. So just get your phone wifi IP and change the last value to 1.
Sub GetGatewayIp As String
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim WifiManager As JavaObject = ctxt.RunMethod("getSystemService", Array(ctxt.GetField("WIFI_SERVICE")))
Dim dhcp As JavaObject = WifiManager.RunMethod("getDhcpInfo", Null)
Dim formatter As JavaObject
Return formatter.InitializeStatic("android.text.format.Formatter").RunMethod("formatIpAddress", Array(dhcp.GetField("gateway")))
End Sub