Reputation: 87
Good morning,
I have created a vb.NET project that pulls the data from WireShark's HTML file found at https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf;hb=HEAD.
So far, I have been able to download the page as a string and search the string to confirm whether or not 'mac' is found in the string.
I would like to have it search for a MAC address, and output the entire line that the MAC appears on.
For example, if I search for 00-00-00-00-00-00 I would like to be able to extract the entire line, "00:00:00 Xerox Xerox Corporation"
This is what I have:
Private Sub btn_search_Click(sender As Object, e As EventArgs) Handles btn_search.Click
Dim mac As String = txt_MAC.Text.ToUpper
Dim pattern As Regex = New Regex("^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$")
Dim match As Match = pattern.Match(mac)
If match.Success Then
mac = mac.Replace("-", ":")
mac = mac.Substring(0, mac.Length - 9)
Dim wc As New Net.WebClient
Dim html As String = wc.DownloadString("https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf;hb=HEAD")
Dim macIndex = html.IndexOf(mac) 'returns line number in string
MsgBox("Valid MAC: " & mac)
If html.Contains(mac) Then
'Display MAC + Vendor. IE.... 0:00:01 Xerox Xerox Corporation'
' Is there a way to read only the specified line number in the string?
End If
Else
MsgBox("You must enter a valid MAC")
End If
End Sub
Any assistance is greatly appreciated.
Upvotes: 0
Views: 250
Reputation: 4385
Instead of parsing HTML files, you can grab the Mac address lookup list as an XML file from the previous link.
Then you can use a snippet like the one in this question "Searching through XML in VB.NET " to lookup though the XML
Upvotes: 1
Reputation: 87
Although a bit sloppy, I was able to do this with the following code:
Dim wc As New Net.WebClient
Dim html As String = wc.DownloadString("https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf;hb=HEAD")
Dim macIndex = html.IndexOf(mac)
If html.Contains(mac) Then
txt_result.Text = "Searching... "
txt_result.Text = html.Chars(macIndex) & html.Chars(macIndex + 1) & html.Chars(macIndex + 2) & html.Chars(macIndex + 3) & html.Chars(macIndex + 4) & html.Chars(macIndex + 5) & html.Chars(macIndex + 6) & html.Chars(macIndex + 7) & html.Chars(macIndex + 8) & html.Chars(macIndex + 9) & html.Chars(macIndex + 10)
Thank you!
Upvotes: 0