胡乱写了一个用于解析MX记录的东西, 有bug。
Imports System.Net.Sockets Imports System.IO Public Class DnsQuery Public Shared Function LookupMX(ByVal Domain As String) As List(Of String) Using UC As New UdpClient, mem As New MemoryStream, bw As New BinaryWriter(mem) UC.Connect("8.8.8.8", 53) bw.Write(CByte(0)) bw.Write(CByte(2)) bw.Write(CByte(1)) bw.Write(CByte(0)) bw.Write(CByte(0)) bw.Write(CByte(1)) bw.Write(CByte(0)) bw.Write(CByte(0)) bw.Write(CByte(0)) bw.Write(CByte(0)) bw.Write(CByte(0)) bw.Write(CByte(0)) For Each substr In Split(Domain, ".") bw.Write(CByte(substr.Length)) For Each c In substr bw.Write(CByte(AscW(c))) Next Next bw.Write(CByte(0)) bw.Write(CByte(0)) bw.Write(CByte(15)) bw.Write(CByte(0)) bw.Write(CByte(1)) Dim ReadySend As Byte() = mem.ToArray UC.Client.Send(ReadySend) Dim Recv(10240) As Byte UC.Client.Receive(Recv) Return Parse(Recv) End Using End Function Public Shared Function Parse(ByVal ansbytes() As Byte) As List(Of String) '这里写的bug很多, 源代码无法放出。 End Function End Class
发表评论