7 Replies - 6223 Views - Last Post: 18 May 2012 - 06:42 AM Rate Topic: -----

#1 kienkiatteo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 16-May 12

Couldn't display the second set of infomations

Posted 17 May 2012 - 02:25 AM

I am trying to display the data I've retrieved from a text file on the datagridview. But I can only display the first set of information on the datagridview. There are 2 set of information.
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)



Is This A Good Question/Topic? 0
  • +

Replies To: Couldn't display the second set of infomations

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Couldn't display the second set of infomations

Posted 17 May 2012 - 06:16 AM

Which of the 479 lines of code you have posted are relevant to your problem? All of them?

I'm only asking because I'd like to know if I need to read all of them to figure out your problem, or if perhaps there are some I can safely ignore. (Perhaps some of the commented out code?) If I have to read all of them, I'll have to block out a couple of hours on the weekend to go over them and see if I can come up with something.

Of course, West Ham and Blackpool are playing to see who gets promoted, and that will be a priority. Then there's Chelsea and Bayern Munich....

If you can narrow it down to maybe 20 or 30 lines, maybe I can get to it a bit quicker.

This post has been edited by BobRodes: 17 May 2012 - 06:20 AM

Was This Post Helpful? 0
  • +
  • -

#3 kienkiatteo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 16-May 12

Re: Couldn't display the second set of infomations

Posted 17 May 2012 - 08:10 AM

Probably 62 to 188. the loop isn't reading line 137 till the Next.
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Couldn't display the second set of infomations

Posted 17 May 2012 - 08:35 AM

Then you first need to look at lines 81 and 137 and see if the former logically excludes the latter.
Was This Post Helpful? 0
  • +
  • -

#5 kienkiatteo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 16-May 12

Re: Couldn't display the second set of infomations

Posted 17 May 2012 - 06:19 PM

I tried changing it and google-ing it but it still doesn't work. Any idea how? Thanks in advance.
Was This Post Helpful? 0
  • +
  • -

#6 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Couldn't display the second set of infomations

Posted 17 May 2012 - 08:56 PM

Quote

I am trying to display the data I've retrieved from a text file on the datagridview. But I can only display the first set of information on the datagridview. There are 2 set of information.

What is the first and what is the second set of data? what you trying to do? are you trying retrieve information from html text?
Was This Post Helpful? 0
  • +
  • -

#7 kienkiatteo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 16-May 12

Re: Couldn't display the second set of infomations

Posted 17 May 2012 - 10:30 PM

Ya i am trying to retrieve the comname, ipadd and macadd( that is one set of data)
There are 2 sets in total from the text file that i had attached. But i can only display the first set. The loop didnt go into the code for 2nd part.
Was This Post Helpful? 0
  • +
  • -

#8 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Couldn't display the second set of infomations

Posted 18 May 2012 - 06:42 AM

I need you to post CheckUser function and UpdateHistory sub. Show screenshot that shows your result, post screenshot how the results should look like. But, it would be best if you attach you project.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1