Private Sub DoDetection()
ListStatus.Rows.Clear()
'listHistory.Rows.Clear()
ReDim IPAddStore(100)
If File.Exists("C:\Program Files (x86)\Wireless Guard\xslt@PAGE=C_2_0.txt") = False Then
Return
End If
Dim Reader As New FileStream("C:\Program Files (x86)\Wireless Guard\xslt@PAGE=C_2_0.txt", FileMode.Open, FileAccess.Read) 'Creating a filestream to open WL_ActiveTable, reading the file only
'Dim Reader2 As New FileStream("C:\Program Files (x86)\Wireless Guard\arp.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite) 'Creating a reader to open arp.txt, opening the file if it exists or creating one if it doesnt exist. Also reads or writes to the file.
Dim Stream1 As New StreamReader(Reader) 'Stream reader to read into WL_ActiveTable.txt
'Dim Stream2 As New StreamWriter(Reader2) 'Stream reader to write into arp.txt
'Dim AString As String = "/SPAN"
'Dim LineIn As String
'Dim InactivePCFound As Integer = 0
'While Stream1.Peek <> -10
' LineIn = Stream1.ReadLine().TrimStart().TrimEnd()
' If LineIn.IndexOf("inactpc", 0) >= 0 Then
' InactivePCFound = 1
' End If
'If InactivePCFound = 0 Then
' If LineIn.IndexOf(AString, 0) >= 0 Then
' Stream2.WriteLine(LineIn)
' End If
'End If
'End While
'Stream1.Dispose()
'Stream2.Dispose()
' MsgBox("File found")
'Else
' MsgBox("Not found")
'End If
'Dim filereader As String
'filereader = My.Computer.FileSystem.ReadAllText("C:\Program Files (x86)\Wireless Guard\xslt@PAGE=C_2_0.txt")
'MsgBox(filereader)
Dim SR As New IO.StreamReader("C:\Program Files (x86)\Wireless Guard\xslt@PAGE=C_2_0.txt")
Dim Lines As String() = Regex.Split(SR.ReadToEnd(), Environment.NewLine)
SR.Close()
Dim Store As String
Dim ComNameSpace As String = ""
Dim IPAddrSpace As String = ""
Dim message As String
Dim macAddrSpace As String = ""
Functioncount = Functioncount + 1
IPAddCount = 0
CountForStoring = 1
Dim indexvalue As Integer = 3
Dim count As Integer = 0
Dim tableslash As Integer = 0
Dim divided As Integer = 0
Dim numberoftimes As Integer = 0
Dim numberoftimes14 As Integer = 0
Dim multiples As Integer
If Lines.Length > 2 Then
For i As Integer = 0 To Lines.Length - 1
'MsgBox(Line)
If Lines(i).Contains("<th>MAC Address") Then
If Lines(Lines.Length - 13).Contains("</table>") Then
tableslash = Lines.Length - 13
count = tableslash - (i + 3)
divided = count Mod 10
If divided = 0 Then
numberoftimes = count \ 12
ElseIf divided <> 0 Then
numberoftimes = count \ 12
numberoftimes14 = divided / 4
End If
End If
For x As Integer = 0 To numberoftimes
multiples = 10
multiples = x * multiples
If Lines((i + indexvalue + multiples)).Contains("<tr>") Then
ComNameSpace = Lines(i + indexvalue + 1 + multiples).Substring(39, ((Lines(i + indexvalue + 1 + multiples).Length) - 44))
If ComNameSpace = "" Then
ComName = "Host"
'ElseIf Lines(i) <> "" Then
'ComName = Lines(i)
Else
ComName = ComNameSpace
ComNameAddStore(IPAddCount) = ComName
End If
ReDim Preserve ComNameAddStore(IPAddCount + 1)
ComNameAddStore(IPAddCount) = ComName
'MsgBox(ComName)
' MsgBox(ComNameAddStore(IPAddCount))
macAddrSpace = Lines(i + indexvalue + 3 + multiples).Substring(22, ((Lines(i + indexvalue + 3 + multiples).Length - 27)))
If macAddrSpace = "" Then
'IPAdd = Lines(i)
MACAdd = "Unknown"
Else
' IPAdd = "Unknown"
MACAdd = macAddrSpace
If MACAdd.Length > 17 Then
MACAdd = MACAdd & " "
MACAdd = macAddrSpace
End If
End If
'MsgBox(MACAdd)
ReDim Preserve MACAddStore(IPAddCount + 1)
MACAddStore(IPAddCount) = MACAdd
IPAddCount = IPAddCount + 1
IPAddrSpace = Lines(i + indexvalue + 4 + multiples).Substring(22, ((Lines(i + indexvalue + 4 + multiples).Length - 27)))
If IPAddrSpace = "" Then
IPAdd = "Unknown"
Else
IPAdd = IPAddrSpace
End If
'MsgBox(IPAdd)
ReDim Preserve IPAddStore(IPAddCount + 1)
ReDim Preserve IPPermStore(IPAddCount + 1)
IPPermStore(IPAddCount - 1) = IPAdd
IPAddStore(IPAddCount - 1) = IPAdd
Store = vbTab & vbTab & ComName & vbTab & vbTab & IPAdd & vbTab & MACAdd
count = count + 1
ElseIf Lines((i + 5 + multiples)).Contains("<tr>") Then
ComNameSpace = Lines(i + 6 + multiples).Substring(39, ((Lines(i + 6 + multiples).Length) - 44))
If ComNameSpace = "" Then
ComName = "Host"
'ElseIf Lines(i) <> "" Then
'ComName = Lines(i)
Else
ComName = ComNameSpace
End If
ReDim Preserve ComNameAddStore(IPAddCount + 1)
ComNameAddStore(IPAddCount) = ComName
'MsgBox(ComName)
macAddrSpace = Lines(i + 10 + multiples).Substring(22, ((Lines(i + 10 + multiples).Length - 27)))
If macAddrSpace = "" Then
'IPAdd = Lines(i)
MACAdd = "Unknown"
Else
' IPAdd = "Unknown"
MACAdd = macAddrSpace
If MACAdd.Length > 17 Then
MACAdd = MACAdd & " "
MACAdd = macAddrSpace
End If
'MsgBox(MACAdd)
End If
ReDim Preserve MACAddStore(IPAddCount + 1)
MACAddStore(IPAddCount) = MACAdd
IPAddCount = IPAddCount + 1
IPAddrSpace = Lines(i + 11 + multiples).Substring(22, ((Lines(i + 11 + multiples).Length - 27)))
If IPAddrSpace = "" Then
IPAdd = "Unknown"
Else
IPAdd = IPAddrSpace
'MsgBox(IPAdd)
End If
ReDim Preserve IPAddStore(IPAddCount + 1)
ReDim Preserve IPPermStore(IPAddCount + 1)
IPPermStore(IPAddCount - 1) = IPAdd
IPAddStore(IPAddCount - 1) = IPAdd
Store = vbTab & vbTab & ComName & vbTab & vbTab & IPAdd & vbTab & MACAdd
count = count + 1
End If
Next
End If
Next
'MsgBox(Lines.Length)
'MsgBox(ComName)
End If
'MsgBox(IPAddCount)
If IPAddCount = 0 Then
'MsgBox(IPAddCount)
Else
'MsgBox(IPAddCount)
For i = 0 To IPAddCount - 1
If (CheckUser(MACAddStore(i)) <> "") Then
RestartAddRow:
Try
ListStatus.Item(0, i).Value = usernameDB
ListStatus.Item(1, i).Value = ComNameAddStore(i)
ListStatus.Item(2, i).Value = IPAddStore(i)
ListStatus.Item(3, i).Value = MACAddStore(i)
ListStatus.DefaultCellStyle.BackColor = Lime
ListStatus.Rows(i).DefaultCellStyle.SelectionBackColor = Lime
Catch ex As Exception
Me.ListStatus.Rows.Add()
GoTo RestartAddRow
End Try
Else
RestartAddRow2:
Try
ListStatus.Item(0, i).Value = "Unknown"
ListStatus.Item(1, i).Value = ComNameAddStore(i)
ListStatus.Item(2, i).Value = IPAddStore(i)
ListStatus.Item(3, i).Value = MACAddStore(i)
ListStatus.Rows(i).DefaultCellStyle.BackColor = Red
ListStatus.Rows(i).DefaultCellStyle.SelectionBackColor = Red
Catch ex As Exception
Me.ListStatus.Rows.Add()
GoTo RestartAddRow2
End Try
End If
Next
End If
If IPAddCount > 0 Then
For i = 0 To IPAddCount - 1
If LastIPAddCount > 0 Then
For j = 0 To LastIPAddCount - 1
If LastMACAddStore(j).IndexOf(MACAddStore(i)) >= 0 Then
Found = 1 'MAC Address was present in the last scan
End If
Next
End If
'Check if new instruder connected to the wifi router
If Found = 0 Then 'not found in last scan
'Check if new instruder connected to the wifi router
If CheckUser(MACAddStore(i)) = "" Then
Try
listHistory.Rows.Add()
listHistory.Item(0, listHistory.Rows.Count - 1).Value = Date.Now
listHistory.Item(1, listHistory.Rows.Count - 1).Value = "Unknown"
listHistory.Item(2, listHistory.Rows.Count - 1).Value = ComNameAddStore(i)
listHistory.Item(3, listHistory.Rows.Count - 1).Value = IPAddStore(i)
listHistory.Item(4, listHistory.Rows.Count - 1).Value = MACAddStore(i)
listHistory.Item(5, listHistory.Rows.Count - 1).Value = "Connected"
message = Date.Now & " " & "Unknown " & vbTab & ComNameAddStore(i) & ComNameSpace & IPAddStore(i) & IPAddrSpace & MACAddStore(i) + " Connected"
UpdateHistory(message)
Catch ex As Exception
End Try
' SMS Notification
SendSMSNotification(MACAddStore(i))
'Check if new authorised users connected to the wifi router
Else
Try
listHistory.Rows.Add()
listHistory.Item(0, listHistory.Rows.Count - 1).Value = Date.Now
listHistory.Item(1, listHistory.Rows.Count - 1).Value = usernameDB
listHistory.Item(2, listHistory.Rows.Count - 1).Value = ComNameAddStore(i)
listHistory.Item(3, listHistory.Rows.Count - 1).Value = IPAddStore(i)
listHistory.Item(4, listHistory.Rows.Count - 1).Value = MACAddStore(i)
listHistory.Item(5, listHistory.Rows.Count - 1).Value = "Connected"
message = Date.Now & " " & usernameDB & vbTab & ComNameAddStore(i) & ComNameSpace & IPAddStore(i) & IPAddrSpace & MACAddStore(i) + " Connected"
UpdateHistory(message)
Catch ex As Exception
End Try
End If
End If
Found = 0
Next
End If
If LastIPAddCount > 0 Then
For i = 0 To LastIPAddCount - 1
If IPAddCount > 0 Then
For j = 0 To IPAddCount - 1
If MACAddStore(j).IndexOf(LastMACAddStore(i)) >= 0 Then
Found = 1
Exit For
End If
Next
End If
If Found = 0 Then 'not found in current scan
'Check if authorized user disconnected from the wifi router
If CheckUser(LastMACAddStore(i)) <> "" Then
Try
listHistory.Rows.Add()
listHistory.Item(0, listHistory.Rows.Count - 1).Value = Date.Now
listHistory.Item(1, listHistory.Rows.Count - 1).Value = usernameDB
listHistory.Item(2, listHistory.Rows.Count - 1).Value = ComNameAddStore(i)
listHistory.Item(3, listHistory.Rows.Count - 1).Value = IPAddStore(i)
listHistory.Item(4, listHistory.Rows.Count - 1).Value = MACAddStore(i)
listHistory.Item(5, listHistory.Rows.Count - 1).Value = "Disconnected"
message = Date.Now & " " & usernameDB & vbTab & LastComNameAddStore(i) & ComNameSpace & LastIPAddStore(i) & IPAddrSpace & LastMACAddStore(i) + " Disconnected"
UpdateHistory(message)
Catch ex As Exception
End Try
'Check if intruder disconnected from the wifi router
Else
Try
listHistory.Rows.Add()
listHistory.Item(0, listHistory.Rows.Count - 1).Value = Date.Now
listHistory.Item(1, listHistory.Rows.Count - 1).Value = "Unknown"
listHistory.Item(2, listHistory.Rows.Count - 1).Value = ComNameAddStore(i)
listHistory.Item(3, listHistory.Rows.Count - 1).Value = IPAddStore(i)
listHistory.Item(4, listHistory.Rows.Count - 1).Value = MACAddStore(i)
listHistory.Item(5, listHistory.Rows.Count - 1).Value = "Disconnected"
message = Date.Now & " " & "Unknown " & vbTab & LastComNameAddStore(i) & ComNameSpace & LastIPAddStore(i) & IPAddrSpace & LastMACAddStore(i) + " Disconnected"
UpdateHistory(message)
Catch ex As Exception
End Try
End If
End If
Found = 0
Next
End If
''Check if new instruder/authorised users connected to the wifi router
'If IPAddCount > 0 Then
' For i = 0 To IPAddCount - 1
' If LastIPAddCount > 0 Then
' For j = 0 To LastIPAddCount - 1
' If LastMACAddStore(j).IndexOf(MACAddStore(i)) >= 0 Then
' Found = 1 'MAC Address was present in the last scan
' 'MsgBox.show("Connected found")
' End If
' 'If LastComNameAddStore(j).IndexOf(ComNameAddStore(i)) >= 0 Then
' ' Found = 1
' 'End If
' Next
' End If
' If Found = 0 Then 'not found in last scan
' If CheckUser(MACAddStore(i)) = "" Then
' AlertRed = New AlertRed
' AlertRed.lbComputerName.Text = ComNameAddStore(i)
' AlertRed.lbIPAddress.Text = IPAddStore(i)
' AlertRed.lbMACAddress.Text = MACAddStore(i)
' AlertRed.Show()
' Else
' AlertGreen = New AlertGreen
' AlertGreen.lbAlertGreen.Text = "Authorized User Connected"
' AlertGreen.lbUserName.Text = usernameDB
' AlertGreen.lbComputerName.Text = ComNameAddStore(i)
' AlertGreen.lbIPAddress.Text = IPAddStore(i)
' AlertGreen.lbMACAddress.Text = MACAddStore(i)
' AlertGreen.Show()
' End If
' End If
' Found = 0
' Next
'End If
''Check if instruder/authorised user disconnected from the wifi router
'If LastIPAddCount > 0 Then
' For i = 0 To LastIPAddCount - 1
' If IPAddCount > 0 Then
' For j = 0 To IPAddCount - 1
' If MACAddStore(j).IndexOf(LastMACAddStore(i)) >= 0 Then
' Found = 1
' 'MsgBox.show("Connected found")
' End If
' Next
' End If
' If Found = 0 Then 'not found in current scan
' If CheckUser(MACAddStore(i)) = "" Then
' AlertRedDisconnected = New AlertRedDisconnected
' AlertRedDisconnected.lbRComputerName.Text = LastComNameAddStore(i)
' AlertRedDisconnected.lbRIPAddress.Text = LastIPAddStore(i)
' AlertRedDisconnected.lbRMACAddress.Text = LastMACAddStore(i)
' AlertRedDisconnected.Show()
' Else
' AlertGreen = New AlertGreen
' AlertGreen.lbAlertGreen.Text = "Authorized User Disconnected"
' AlertGreen.lbComputerName.Text = LastComNameAddStore(i)
' AlertGreen.lbIPAddress.Text = LastIPAddStore(i)
' AlertGreen.lbMACAddress.Text = LastMACAddStore(i)
' AlertGreen.Show()
' End If
' End If
' Found = 0
' Next
'End If
LastIPAddCount = IPAddCount
If IPAddCount > 0 Then
MACAddStore.CopyTo(LastMACAddStore, 0)
IPAddStore.CopyTo(LastIPAddStore, 0)
ComNameAddStore.CopyTo(LastComNameAddStore, 0)
'For i = 0 To IPAddCount - 1
' If MACAddStore(i).Length > 0 Then
' MACAddStore(i).CopyTo(0, LastMACAddStore(i), 0, MACAddStore(i).Length)
' End If
'Next
End If
'If IPAddCount = 0 Then
'Else
' For i = 0 To IPAddCount - 1
' If CheckUser(MACAddStore(i)) = False Then
' AlertRed = New AlertRed
' AlertRed.lbComputerName.Text = ComNameAddStore(i)
' AlertRed.lbIPAddress.Text = IPAddStore(i)
' AlertRed.lbMACAddress.Text = MACAddStore(i)
' AlertRed.Show()
' Else
' AlertGreen = New AlertGreen
' AlertGreen.lbComputerName.Text = ComNameAddStore(i)
' AlertGreen.lbIPAddress.Text = IPAddStore(i)
' AlertGreen.lbMACAddress.Text = MACAddStore(i)
' AlertGreen.Show()
' End If
' Next
'End If
'Dim sr2 As New System.IO.StreamReader("C:\\Program Files (x86)\\Wireless Guard\\bin\\WWAuthorizedUser.mdb")
'Dim tempstr As String = sr2.ReadLine
'While Not S = ""
' ReDim Preserve MACAddStore(IPAddCount)
' MACAddStore(IPAddCount) = tempstr
' tempstr = sr2.ReadLine
'End While
Try
ListStatus.Rows(lastSelected).Selected = True
Catch ex As Exception
Try
ListStatus.Rows(ListStatus.Rows.Count - 1).Selected = True
Catch es As Exception
End Try
End Try
ListStatus.Refresh()
listHistory.Refresh()
listHistory.Visible = False
listHistory.Visible = True
End Sub
Attached File(s)
-
xslt@PAGE=C_2_0.zip (1.61K)
Number of downloads: 16

New Topic/Question
Reply



MultiQuote



|