问题:--我正在寻找一个mDNS包,同时在堆栈流中搜索选项。我尝试了bonjour和一些包装器,但是取得了非常有限的成功,特别是当我第二次请求并收到套接字绑定投诉时(当然,这可能是我的代码而不是它们)。
因为据我所知,VB.net没有一个真正可编辑的DNS层,所以我在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,我还应该添加或更改什么?我能在domainName里放些什么?我应该改变一下等级吗?
我们绝对欢迎所有或任何建议。
发布于 2014-07-17 18:36:17
如果其他需要在mDNS中使用vb.net的人需要这样做,我将回答我的问题:
解决方案:--我不需要向DNS层添加任何内容就可以完成这项工作。我将DNS层更改为:
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 _
}我将Ipv4层的输出地址改为"224.0.0.251“的多播地址,将端口更改为5353,并使用了上述问题的域名。
这里有一个wireshark来展示你的回答:

https://stackoverflow.com/questions/24810544
复制相似问题