regex - VB.NET MAC OUI 查找
问题描述
早上好,
我创建了一个 vb.NET 项目,它从位于https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf;hb=HEAD的 WireShark 的 HTML 文件中提取数据。
到目前为止,我已经能够将页面下载为字符串并搜索字符串以确认是否在字符串中找到“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
非常感谢任何帮助。
解决方案
您可以从上一个链接中获取作为 XML 文件的Mac 地址查找列表,而不是解析 HTML 文件。
然后,您可以使用类似于此问题“Searching through XML in VB.NET”中的片段来查找 XML
推荐阅读
- javascript - 如何在我的测验机器人中显示下一个问题并修复错误?
- flutter - 未处理的异常:NoSuchMethodError:在 null 上调用了方法“close”。颤振块
- c - 是否保证在 C 中使用 CLOCKS_PER_SEC 获得 1 秒?
- c++ - 无向图移除
- c++ - Cmake C++ 项目与 src 中的特征标头
- git - 运行子模块更新时,为什么不总是使用--init?
- docker - bitwarden_rs 在 traefik v2.2(坏网关)后面不工作
- wikipedia - 扩展完整维基百科转储的维基文本的最佳方法是什么?
- android - 获取收到短信的号码(双卡)
- c - 从闪存STM32F1中读取特定地址的内容