問題:我正在尋找一個mDNS數據包,同時搜索stackflow的選項。我嘗試了Bonjour和一些包裝,但成功非常有限,尤其是當我第二次請求並獲得套接字綁定投訴時(當然,這可能是我的代碼而不是它們)。我怎樣才能使用Pcap.net進行mDNS查詢?
由於VB.net沒有我知道的真正可編輯的dnsquery,我在pcapdotnet中使用構建DNS數據包中的DNS層,並且只是逐層製作數據包。我認爲這是一個很好的選擇,但我有點失落,我會怎麼做。
下面是我們想要的問題:
q_name = new QuestionName("_axis-video._tcp.local"),
q_type = QuerryConstants.Question.QuestionType.PTR,
q_class = QuerryConstants.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嗎?
絕對歡迎所有或任何建議。