Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Socket1 As Socket
Dim PingTimer,PingTimer2,PingTimer3,PingTimer4,PingTimer5,PingTimer6,PingTimer7,PingTimer8 As Timer
Dim IPAddress As String
Dim IPPort As String : IPPort = "135"
Dim MachineNode As Int : MachineNode = 2
Dim NetworkNode As Int : NetworkNode = 1
Dim lblInfo As Label
Dim lstPings As ListView
Dim inicio, final As Int
Dim btnEscanea As Button
Dim txtIp4 As EditText
Dim txtIp8 As EditText
Dim txtIp3 As EditText
Dim timerActual As Int
Dim infostring As String
Dim ipp As Object
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Activity.LoadLayout("menu")
PingTimer.Initialize("PingTimer", 50)
PingTimer2.Initialize("PingTimer2", 50)
PingTimer3.Initialize("PingTimer3", 50)
PingTimer4.Initialize("PingTimer4", 50)
PingTimer5.Initialize("PingTimer5", 50)
PingTimer6.Initialize("PingTimer6", 50)
PingTimer7.Initialize("PingTimer7", 50)
PingTimer8.Initialize("PingTimer8", 50)
Activity.AddMenuItem("Salir","Salida")
End If
'Formato del listview
'Tamaño de letra del listview
Dim Lb As Label
Lb = lstPings.SingleLineLayout.Label
Lb.Textsize = 12
'Alto de filas del listview
lstPings.SingleLineLayout.ItemHeight = 50
End Sub
'Salir de la aplicación
Sub Salida_Click()
Activity.Finish
ExitApplication
End Sub
Sub Socket1_Connected (Successful As Boolean)
If Successful Then
'Si el elemento no está en la lista
If CompruebaLista(IPAddress) = False Then
infostring = GetHostName(IPAddress)
lstPings.AddSingleLine(IPAddress&" "&infostring)
'
Socket1.Close
End If
Else
If timerActual = 1 Then PingTimer.Enabled = True
If timerActual = 2 Then PingTimer2.Enabled = True
If timerActual = 3 Then PingTimer3.Enabled = True
If timerActual = 4 Then PingTimer4.Enabled = True
If timerActual = 5 Then PingTimer5.Enabled = True
If timerActual = 6 Then PingTimer6.Enabled = True
If timerActual = 7 Then PingTimer7.Enabled = True
End If
End Sub
'Escanear puerto 80 HTTP
Sub PingTimer_Tick
PingTimer.Enabled = False
MachineNode = MachineNode + 1
If MachineNode <= final Then
IPAddress = "192.168." & NetworkNode & "." & MachineNode
lblInfo.Text = "Trying " & IPAddress & " on port 80"
Socket1.Close
Socket1.Initialize("Socket1")
Socket1.Connect(IPAddress, 80, 1000)
PingTimer.Enabled = True
Else
PingTimer.Enabled = False
MachineNode = 0
timerActual = 2
PingTimer2.Enabled = True
End If
End Sub
'Escanear puerto 135 NETBIOS
Sub PingTimer2_Tick
PingTimer2.Enabled = False
MachineNode = MachineNode + 1
If MachineNode <= final Then
IPAddress = "192.168." & NetworkNode & "." & MachineNode
lblInfo.Text = "Trying " & IPAddress & " on port 135"
Socket1.Close
Socket1.Initialize("Socket1")
Socket1.Connect(IPAddress, 135, 1000)
PingTimer2.Enabled = True
Else
PingTimer2.Enabled = False
MachineNode = 0
timerActual = 3
PingTimer3.Enabled = True
End If
End Sub
'Escanear puerto 139 SHARED
Sub PingTimer3_Tick
PingTimer3.Enabled = False
MachineNode = MachineNode + 1
If MachineNode <= final Then
IPAddress = "192.168." & NetworkNode & "." & MachineNode
lblInfo.Text = "Trying " & IPAddress & " on port 139"
Socket1.Close
Socket1.Initialize("Socket1")
Socket1.Connect(IPAddress, 139, 1000)
PingTimer3.Enabled = True
Else
PingTimer3.Enabled = False
MachineNode = 0
timerActual = 4
PingTimer4.Enabled = True
End If
End Sub
'Escanear puerto 21 FTP
Sub PingTimer4_Tick
PingTimer4.Enabled = False
MachineNode = MachineNode + 1
If MachineNode <= final Then
IPAddress = "192.168." & NetworkNode & "." & MachineNode
lblInfo.Text = "Trying " & IPAddress & " on port 21"
Socket1.Close
Socket1.Initialize("Socket1")
Socket1.Connect(IPAddress, 139, 1000)
PingTimer4.Enabled = True
Else
PingTimer4.Enabled = False
MachineNode = 0
timerActual = 5
PingTimer5.Enabled = True
End If
End Sub
'Escanear puerto 22 SSH
Sub PingTimer5_Tick
PingTimer5.Enabled = False
MachineNode = MachineNode + 1
If MachineNode <= final Then
IPAddress = "192.168." & NetworkNode & "." & MachineNode
lblInfo.Text = "Trying " & IPAddress & " on port 22"
Socket1.Close
Socket1.Initialize("Socket1")
Socket1.Connect(IPAddress, 139, 1000)
PingTimer5.Enabled = True
Else
PingTimer5.Enabled = False
MachineNode = 0
timerActual = 6
PingTimer6.Enabled = True
End If
End Sub
'Escanear puerto 23 TELNET
Sub PingTimer6_Tick
PingTimer6.Enabled = False
MachineNode = MachineNode + 1
If MachineNode <= final Then
IPAddress = "192.168." & NetworkNode & "." & MachineNode
lblInfo.Text = "Trying " & IPAddress & " on port 23"
Socket1.Close
Socket1.Initialize("Socket1")
Socket1.Connect(IPAddress, 139, 1000)
PingTimer6.Enabled = True
Else
PingTimer6.Enabled = False
MachineNode = 0
timerActual = 7
PingTimer7.Enabled = True
End If
End Sub
'Escanear puerto 3389 RDP
Sub PingTimer7_Tick
PingTimer7.Enabled = False
MachineNode = MachineNode + 1
If MachineNode <= final Then
IPAddress = "192.168." & NetworkNode & "." & MachineNode
lblInfo.Text = "Trying " & IPAddress & " on port 3389"
Socket1.Close
Socket1.Initialize("Socket1")
Socket1.Connect(IPAddress, 139, 1000)
PingTimer7.Enabled = True
Else
PingTimer7.Enabled = False
MachineNode = 0
timerActual = 8
PingTimer8.Enabled = True
End If
End Sub
'Escanear puerto 445 SMB over TCP
Sub PingTimer8_Tick
PingTimer8.Enabled = False
MachineNode = MachineNode + 1
If MachineNode <= final Then
IPAddress = "192.168." & NetworkNode & "." & MachineNode
lblInfo.Text = "Trying " & IPAddress & " on port 445"
Socket1.Close
Socket1.Initialize("Socket1")
Socket1.Connect(IPAddress, 445, 1000)
PingTimer8.Enabled = True
Else
PingTimer8.Enabled = False
lblInfo.Text = lstPings.Size & " dispositivos encontrados"
ToastMessageShow("Escaneo completado",False)
End If
End Sub
'Comprobar si el elemento ya está en la lista
Sub CompruebaLista(texto As String) As Boolean
For i=0 To lstPings.Size - 1
If lstPings.GetItem(i) = texto Then
Return True
End If
Next
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'Empieza a escanear
Sub btnEscanea_Click
inicio = txtIp4.Text
final = txtIp8.Text
NetworkNode = txtIp3.text
MachineNode = inicio-1
PingTimer.Enabled = True
timerActual = 1
End Sub
Sub GetHostName(IP As String) As String
Dim r As Reflector
r.Target = r.RunStaticMethod("java.net.InetAddress", "getByName", Array As Object(IP), _
Array As String("java.lang.String"))
If r.Target = Null Then Return "N/A"
Return r.RunMethod("getCanonicalHostName")
End Sub