VB.NET MAC OUI查找

时间:2018-10-05 17:49:49

标签: regex vb.net extract mac-address

早上好

我创建了一个vb.NET项目,该项目从WireShark的HTML文件中提取数据,该文件位于https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf;hb=HEAD

到目前为止,我已经能够以字符串形式下载页面并搜索该字符串以确认是否在字符串中找到了“ mac”。

我想让它搜索MAC地址,并输出MAC出现的整行。

例如,如果我搜索00-00-00-00-00-00,我希望能够提取整行“ 00:00:00 Xerox Xerox Corporation”

这就是我拥有的:

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

我们非常感谢您的协助。

2 个答案:

答案 0 :(得分:0)

虽然有点草率,但我可以使用以下代码来做到这一点:

        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)

谢谢!

答案 1 :(得分:0)

您可以从上一个链接中将Mac address lookup list捕获为XML文件,而不是解析HTML文件。

然后,您可以使用此问题"Searching through XML in VB.NET "中的代码段通过XML查找