Sub GetPropInfo As String
' Libs: Core (v/2.47), Phone (v/2.01)
Dim P As Phone
Dim sb As StringBuilder
Dim i, iNetMask, iIP As Int
Dim PropData(), sCurrentIP(), sNetMask() As String
Dim sWifi, sModel, sSdk, sVersion, sIP, sMask, sGate, sD1, sD2, sBCAddr, sTmp As String
ProgressDialogShow("Please wait")
sb.Initialize
P.Shell("getprop", Null, sb, Null)
PropData = Regex.Split(CRLF,sb.ToString)
For i = 0 To PropData.Length - 1
' What is the Wifi Interface called?
If PropData(i).Contains("[wifi.interface]") Then
sWifi = PropData(i)
sWifi = sWifi.Replace("[","")
sWifi = sWifi.Replace("]","")
sWifi = sWifi.SubString(sWifi.IndexOf(" ")).Trim
Exit
End If
Next
If sWifi.Length > 0 Then
For i = 0 To PropData.Length - 1
If PropData(i).Contains("[ro.product.model]") Then
sModel = PropData(i)
sModel = sModel.Replace("[","")
sModel = sModel.Replace("]","")
sModel = sModel.SubString(sModel.IndexOf(" ")).Trim
End If
If PropData(i).Contains("[ro.build.version.sdk]") Then
sSdk = PropData(i)
sSdk = sSdk.Replace("[","")
sSdk = sSdk.Replace("]","")
sSdk = sSdk.SubString(sSdk.IndexOf(" ")).Trim
End If
If PropData(i).Contains("[ro.build.version.release]") Then
sVersion = PropData(i)
sVersion = sVersion.Replace("[","")
sVersion = sVersion.Replace("]","")
sVersion = sVersion.SubString(sVersion.IndexOf(" ")).Trim
End If
' *******************************************************************
If PropData(i).Contains("[dhcp." & sWifi & ".ipaddress]") Then
sIP = PropData(i)
sIP = sIP.Replace("[","")
sIP = sIP.Replace("]","")
sIP = sIP.SubString(sIP.IndexOf(" ")).Trim
End If
If PropData(i).Contains("[dhcp." & sWifi & ".mask]") Then
sMask = PropData(i)
sMask = sMask.Replace("[","")
sMask = sMask.Replace("]","")
sMask = sMask.SubString(sMask.IndexOf(" ")).Trim
End If
If PropData(i).Contains("[dhcp." & sWifi & ".gateway]") Then
sGate = PropData(i)
sGate = sGate.Replace("[","")
sGate = sGate.Replace("]","")
sGate = sGate.SubString(sGate.IndexOf(" ")).Trim
End If
If PropData(i).Contains("[dhcp." & sWifi & ".dns1]") Then
sD1 = PropData(i)
sD1 = sD1.Replace("[","")
sD1 = sD1.Replace("]","")
sD1 = sD1.SubString(sD1.IndexOf(" ")).Trim
End If
If PropData(i).Contains("[dhcp." & sWifi & ".dns2]") Then
sD2 = PropData(i)
sD2 = sD2.Replace("[","")
sD2 = sD2.Replace("]","")
sD2 = sD2.SubString(sD2.IndexOf(" ")).Trim
End If
DoEvents
Next
sCurrentIP = Regex.Split("\.",sIP)
sNetMask = Regex.Split("\.",sMask)
sBCAddr = ""
For i = 0 To 3
iIP = Val(sCurrentIP(i).Trim)
iNetMask = Val(sNetMask(i).Trim)
sTmp = DecToBin(iNetMask,8)
sTmp = ReverseBits(sTmp)
iNetMask = BinToDec(sTmp)
sBCAddr = sBCAddr & Bit.OR(iIP,iNetMask)
If i < 3 Then sBCAddr = sBCAddr & "."
Next
ProgressDialogHide
Return "Model: " & sModel & CRLF & _
"Android v/ " & sVersion & CRLF & _
"SDK v/ " & sSdk & CRLF & CRLF & _
"Wifi Interface: " & sWifi & CRLF & _
"IP Address: " & sIP & CRLF & _
"Subnet Mask: " & sMask & CRLF & _
"Broadcast Addr.: " & sBCAddr & CRLF & _
"Default Gateway: " & sGate & CRLF & _
"DNS #1: " & sD1 & CRLF & _
"DNS #2: " & sD2 & CRLF
Else
Return "Wifi Interface not found."
End If
End Sub
Sub DecToBin(decVal As Int, NumBit As Int) As String
Dim bits As Int
Dim dec2bin As StringBuilder
dec2bin.Initialize
If NumBit = 0 Then
Do While decVal > Power(2,bits)-1
bits = bits + 1
Loop
Else
bits = NumBit
End If
For i = bits-1 To 0 Step -1
dec2bin.Append((Bit.AND(decVal, Power(2,i)))/Power(2,i))
Next
Return dec2bin
End Sub
Sub BinToDec(binVal As String) As Int
Dim i, v, dec As Int
i = binVal.Length
v = 1
For pos = i To 1 Step -1
If binVal.SubString2(pos-1, pos) = "1" Then dec = dec + v
v = v * 2
Next
Return dec
End Sub
Sub Val(sNum As String) As Int
If IsNumber(sNum.Trim) Then
Return sNum.Trim
Else
Return -1
End If
End Sub
Sub ReverseBits(sBin As String) As String
Dim i As Int
Dim sOut As String
For i = 0 To sBin.Length - 1
If sBin.CharAt(i) = "0" Then
sOut = sOut & "1"
Else If sBin.CharAt(i) = "1" Then
sOut = sOut & "0"
End If
Next
Return sOut
End Sub