问题:我正在寻找一个 mDNS 数据包,同时在堆栈流中搜索选项。我尝试了 bonjour 和一些包装器,但成功非常有限,尤其是当我第二次请求并收到套接字绑定投诉时(当然,这可能是我的代码而不是它们)。
由于 VB.net 没有我所知道的真正可编辑的 dnsquery,因此我在 pcapdotnet 的构建 DNS 数据包中使用了 DNS 层,只是自己一层一层地制作数据包。我认为这是一个不错的选择,但我对如何做到这一点有点迷茫。
这是我们想要的问题:
q_name = new QuestionName("_axis-video._tcp.local"),
q_type = QueryConstants.Question.QuestionType.PTR,
q_class = QueryConstants.Question.QuestionClass.IN
这是我根据他们的标准编辑的 BuildDNSPacket 函数:
Private Shared Function BuildDnsPacket(destmac As String, domainName As String) As Packet
'get source MAC address of PC
Dim nic = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
Dim source As String = nic(0).GetPhysicalAddress().ToString
Dim sourcearray As Byte() = System.Text.Encoding.ASCII.GetBytes(source)
'format
Dim sourceMacStr As String = ""
For i As Integer = 0 To sourcearray.Count - 1 Step 2
sourceMacStr += Chr(sourcearray(i)) & Chr(sourcearray(i + 1)) & ":"
Next
' Will be filled automatically.
Dim ethernetLayer As New EthernetLayer() With { _
.Source = New MacAddress(sourceMacStr.Substring(0, 17)), _
.Destination = New MacAddress(destmac), _
.EtherType = EthernetType.None _
}
' Will be filled automatically.
Dim ipV4Layer As New IpV4Layer() With { _
.Source = New IpV4Address("1.2.3.4"), _
.CurrentDestination = New IpV4Address(destmac), _
.Fragmentation = IpV4Fragmentation.None, _
.HeaderChecksum = Nothing, _
.Identification = 123, _
.Options = IpV4Options.None, _
.Protocol = Nothing, _
.Ttl = 100, _
.TypeOfService = 0 _
}
' Will be filled automatically.
Dim udpLayer As New UdpLayer() With { _
.SourcePort = 5353, _
.DestinationPort = 5353, _
.Checksum = Nothing, _
.CalculateChecksumValue = False _
}
Dim dnsLayer As New DnsLayer() With { _
.Id = 0, _
.IsResponse = False, _
.OpCode = DnsOpCode.Query, _
.IsAuthoritativeAnswer = False, _
.IsTruncated = False, _
.IsRecursionDesired = False, _
.IsRecursionAvailable = False, _
.FutureUse = False, _
.IsAuthenticData = False, _
.IsCheckingDisabled = False, _
.ResponseCode = DnsResponseCode.NoError, _
.Queries = {New DnsQueryResourceRecord(New DnsDomainName(domainName), DnsType.Ptr, DnsClass.Any)}, _
.Answers = Nothing, _
.Authorities = Nothing, _
.Additionals = Nothing, _
.DomainNameCompressionMode = DnsDomainNameCompressionMode.All _
}
Dim builder As New PacketBuilder(ethernetLayer, ipV4Layer, udpLayer, dnsLayer)
Return builder.Build(DateTime.Now)
End Function
主要区别是我将 DnsType 更改为 PTR 并将端口更改为 5353。
问题:我还应该添加或更改什么以使其成为 mDNS?我可以在域名中添加什么?我应该改变 dnsclass 吗?
绝对欢迎所有或任何建议。