Results 1 to 12 of 12

Thread: DNS Server in VB6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    28

    Question 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

  2. #2
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    554

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    28

    Re: DNS Server in VB6

    Quote Originally Posted by Code Dummy View Post
    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.

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    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)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    28

    Post 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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    28

    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?

  7. #7
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    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.

  8. #8
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    554

    Re: DNS Server in VB6

    Quote Originally Posted by software07 View Post
    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

  9. #9
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: DNS Server in VB6

    Quote Originally Posted by Code Dummy View Post
    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.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    28

    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:
    Name:  Screenshot.png
Views: 1636
Size:  4.8 KB

    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 }

  11. #11
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    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.

  12. #12
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,470

    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
  •  



Click Here to Expand Forum to Full Width