80 lines
2.8 KiB
VB.net
80 lines
2.8 KiB
VB.net
|
|
|
|||
|
|
|
|||
|
|
Imports System.Net
|
|||
|
|
Imports System.Net.Sockets
|
|||
|
|
Imports System.Threading
|
|||
|
|
Imports ARSoft.Tools.Net
|
|||
|
|
Imports ARSoft.Tools.Net.Dns
|
|||
|
|
Imports AutoFixture
|
|||
|
|
Imports DnsClient
|
|||
|
|
|
|||
|
|
Public Class CxDnsServer
|
|||
|
|
Public QUERY_TIMEOUT As Integer = 1000
|
|||
|
|
Public dnsAddr As String
|
|||
|
|
Public domain As String
|
|||
|
|
Public G_DnsThread As Thread
|
|||
|
|
Public Sub New()
|
|||
|
|
' Dim dnsServer As DnsServer = New DnsServer
|
|||
|
|
'G_DnsThread = New Thread(New ThreadStart(AddressOf runingDnsClient))
|
|||
|
|
'G_DnsThread.Start()
|
|||
|
|
End Sub
|
|||
|
|
Public Sub runingDnsClient()
|
|||
|
|
If String.IsNullOrEmpty(domain) Then
|
|||
|
|
MsgBox("待解析的域名不可为空")
|
|||
|
|
Return
|
|||
|
|
End If
|
|||
|
|
If String.IsNullOrEmpty(dnsAddr) Then
|
|||
|
|
MessageBox.Show("DNS地址不可为空")
|
|||
|
|
End If
|
|||
|
|
Dim isDomainName As ARSoft.Tools.Net.DomainName = ARSoft.Tools.Net.DomainName.Parse(domain)
|
|||
|
|
Dim isdnsClient As ARSoft.Tools.Net.Dns.DnsClient = New ARSoft.Tools.Net.Dns.DnsClient(IPAddress.Parse(dnsAddr), QUERY_TIMEOUT)
|
|||
|
|
Dim isDnsMessage As DnsMessage = isdnsClient.Resolve(isDomainName, RecordType.A)
|
|||
|
|
If IsNothing(isDnsMessage) OrElse (isDnsMessage.ReturnCode <> ReturnCode.NoError And isDnsMessage.ReturnCode <> ReturnCode.NxDomain) Then
|
|||
|
|
MsgBox("没有解析成功")
|
|||
|
|
Else
|
|||
|
|
For Each tdnsRecord In isDnsMessage.AnswerRecords
|
|||
|
|
Dim taRecord As ARecord = TryCast(tdnsRecord, ARecord)
|
|||
|
|
If IsNothing(taRecord) Then
|
|||
|
|
MsgBox($"解析成功{taRecord.Address.ToString }{vbCrLf }")
|
|||
|
|
Else
|
|||
|
|
Continue For
|
|||
|
|
End If
|
|||
|
|
Next
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
Public dnsServer As DnsServer
|
|||
|
|
Public Sub runingDnsServer(ipadd As IPAddress)
|
|||
|
|
If Not IsNothing(dnsServer) Then
|
|||
|
|
dnsServer.Stop()
|
|||
|
|
End If
|
|||
|
|
dnsServer = New DnsServer(ipadd, 50, 50)
|
|||
|
|
dnsServer.Start()
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
|
|||
|
|
Private Function ProcessQuery(ByVal message As DnsMessageBase, ByVal clientAddress As IPAddress, ByVal protocol As ProtocolType) As DnsMessageBase
|
|||
|
|
message.IsQuery = False
|
|||
|
|
Dim query As DnsMessage = TryCast(message, DnsMessage)
|
|||
|
|
|
|||
|
|
If query Is Nothing OrElse query.Questions.Count <= 0 Then
|
|||
|
|
message.ReturnCode = ReturnCode.ServerFailure
|
|||
|
|
Else
|
|||
|
|
|
|||
|
|
If query.Questions(0).RecordType = RecordType.A Then
|
|||
|
|
|
|||
|
|
For Each dnsQuestion As ARSoft.Tools.Net.Dns.DnsQuestion In query.Questions
|
|||
|
|
'Dim resolvedIp As String = Resolve(clientAddress.ToString(), dnsQuestion.Name)
|
|||
|
|
'Dim aRecord As ARecord = New ARecord(query.Questions(0).Name, 36000, IPAddress)
|
|||
|
|
'query.AnswerRecords.Add(aRecord)
|
|||
|
|
Next
|
|||
|
|
Else
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Return message
|
|||
|
|
End Function
|
|||
|
|
End Class
|