-
May 10th, 2017, 11:19 AM
#1
Thread Starter
Junior Member
DNS Server in VB6
I have found many examples on the internet about making web servers but haven't found any about DNS servers. I am just curious about making it. Is possible with winsock? Any idea where to start?
Last edited by software07; May 10th, 2017 at 11:23 AM.
Reason: added line
-
May 10th, 2017, 11:48 AM
#2
Fanatic Member
Re: DNS Server in VB6
Do you know what a DNS server is? If yes, can you explain to me (and any one else) exactly what it is and how it works
-
May 10th, 2017, 11:56 AM
#3
Thread Starter
Junior Member
Re: DNS Server in VB6
Originally Posted by Code Dummy
Do you know what a DNS server is? If yes, can you explain to me (and any one else) exactly what it is and how it works
Yes, DNS is Domain Name System server. It converts domain names to the numerical IP addresses. What I am trying to make is a Captive Portal which I very often find on Wi-Fi networks. A captive portal doesn't let you browse the internet unless you login (on the web browser). The captive portal redirects to the login page even if you try to open any other website. That's where I think DNS servers are involved, so I am trying to learn if it works that way and also trying to make one of my own.
-
May 10th, 2017, 12:01 PM
#4
Re: DNS Server in VB6
DNS is just another service that listens on UDP so as long as winsock can do that there is no reason this couldn't be done.
As a starting point https://en.wikipedia.org/wiki/Domain_Name_System gives an overview of what is involved and the relevant RFCs that define how DNS works.
As a bare minimum you would ned a server that listens on UDP port 53 and can decode a typical client query message and then send an appropriate response (https://www.ietf.org/rfc/rfc1035.txt is the rather dry standard documenting all the potential messages)
-
May 11th, 2017, 11:22 PM
#5
Thread Starter
Junior Member
Re: DNS Server in VB6
I have written the code for the Server which listens on UDP port 53. Require help for next steps.
Code:
Private Sub Command1_Click()
Text1.text = Text1.text & "Server started." & vbCrLf
Winsock1.Protocol = sckUDPProtocol
Winsock1.LocalPort = 53
Winsock1.Bind
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Command1.Enabled = True
Command2.Enabled = False
Winsock1.Close
Text1.text = Text1.text & "Server stopped." & vbCrLf
End Sub
Private Sub Form_Load()
Command2.Enabled = False
Winsock1.Close
Command1.Caption = "Start"
Command2.Caption = "Stop"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim WinsockData As String
Winsock1.GetData WinsockData
Text1.text = Text1.text & "Recieved: " & WinsockData & vbCrLf
End Sub
-
May 12th, 2017, 12:21 AM
#6
Thread Starter
Junior Member
Re: DNS Server in VB6
I changed the DNS Server of my connection to 127.0.0.1 and it did get the requests but there are weird characters in the requst. How can I parse the request data?
-
May 12th, 2017, 06:13 AM
#7
Re: DNS Server in VB6
Could you post an example of what you are seeing regarding the "weird characters", you could try using GetData with a type of vbByte to get the raw data.
I suspect the problem is that a DNS client request isn't plain text - it is a binary format you will need to decode. The links I posted earlier should have all the documentation needed to process these requests though.
-
May 12th, 2017, 11:57 AM
#8
Fanatic Member
Re: DNS Server in VB6
Originally Posted by software07
I changed the DNS Server of my connection to 127.0.0.1 and it did get the requests but there are weird characters in the requst. How can I parse the request data?
Can you explain this. How did you change the IP of your server when IP is determined by the OS
-
May 12th, 2017, 01:33 PM
#9
Re: DNS Server in VB6
Originally Posted by Code Dummy
Can you explain this. How did you change the IP of your server when IP is determined by the OS
A computer's IP is not always determined by the OS, most computers get their ip from a DHCP server but you can go into the network card's settings and change it to whatever you like (unless you know what addresses are valid though you run the risk of losing network connectivity).
If you are getting an address automatically then it will normally also set things lik subnet mask, default gateway and dns server addresses - you can certainly go in and change the dns to whatever server you like, obviously if you point it to an address not running DNS then you will lose name resolution. Setting it to 127.0.0.1 is simply making the computer use itself as a DNS server, which makes sense if you are trying to debug a DNS server you are running on your local machine.
If your computer is on a corporate network then there is a very high chance that you will not have permissions to make these changes, but anyone with admin rights can do this.
-
May 12th, 2017, 11:44 PM
#10
Thread Starter
Junior Member
Re: DNS Server in VB6
I have used the code StrConv(WinsockData, vbUnicode) in a RTF Textbox and I could get some readable information.
Screenshot:
RTF Text:
Code:
{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang1033\f0\fs17 Server started.
\par Recieved: \'c8\'00\'dd\'00\'01\'00\'00\'00\'00\'00\'01\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'03\'00w\'00w\'00w\'00\'06\'00g\'00o\'00o\'00g\'00l\'00e\'00\'02\'00c\'00o\'00\'02\'00i\'00n\'00\'00\'00\'00\'00\'01\'00\'00\'00\'01\'00
\par Recieved: \'c8\'00\'dd\'00\'01\'00\'00\'00\'00\'00\'01\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'03\'00w\'00w\'00w\'00\'06\'00g\'00o\'00o\'00g\'00l\'00e\'00\'02\'00c\'00o\'00\'02\'00i\'00n\'00\'00\'00\'00\'00\'01\'00\'00\'00\'01\'00
\par Recieved: \'c8\'00\'dd\'00\'01\'00\'00\'00\'00\'00\'01\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'03\'00w\'00w\'00w\'00\'06\'00g\'00o\'00o\'00g\'00l\'00e\'00\'02\'00c\'00o\'00\'02\'00i\'00n\'00\'00\'00\'00\'00\'01\'00\'00\'00\'01\'00
\par Recieved: \'c8\'00\'dd\'00\'01\'00\'00\'00\'00\'00\'01\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'00\'03\'00w\'00w\'00w\'00\'06\'00g\'00o\'00o\'00g\'00l\'00e\'00\'02\'00c\'00o\'00\'02\'00i\'00n\'00\'00\'00\'00\'00\'01\'00\'00\'00\'01\'00
\par Server stopped.
\par
\par }
-
May 13th, 2017, 10:57 AM
#11
Re: DNS Server in VB6
Unfortunately the data you are receiving isn't text, it is a mixture of binary fields and text fields - https://www.ietf.org/rfc/rfc1035.txt section 4.1 is probably a good place to start if you want to understand these formats.
Rather than formatting the query as text could you post the raw bytes received here? Having the raw data might make it easier for someone to help interpret them.
-
May 13th, 2017, 11:11 PM
#12
Re: DNS Server in VB6
DNS packets are very compact and highly cryptic, and I caution you that what you are attempting is far from simple. I recently posted a Client DNS program in the codebank:
http://www.vbforums.com/showthread.p...-VB6-ClientDNS
I used SimpleSock for the latest version rather than MS Winsock, because it is simpler and easier to use. But it does demonstrates both sides of the DNS conversation. SimpleSock supports both IPv4 & IPv6, so it only works on Vista or better.
J.A. Coutts
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|