Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 626019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:22:23+00:00 2026-05-13T19:22:23+00:00

I know how to look up a hostname from an IPv4 in VB using

  • 0

I know how to look up a hostname from an IPv4 in VB using the GetHostByAddr Windows API call (this works great). However, that function does not allow one to specify the DNS server to use. Sometimes the default company DNS servers are fine, but other times I need to specify an external DNS server for lookups, and I don’t think doing a shell nslookup and parsing the output is the best method, here.

Note: this is actually going to be used as VBA code in an Excel workbook to help someone else do his job, and it’s not worth writing a big application when some simple functionality is all he needs.

I thought I had possibly found an answer in the API call getnameinfo but careful reading seems to indicate it does not offer a servername parameter.

After some intense searching, I found reference to the pExtra parameter to the DNSQuery function. But I don’t even know how to begin to use that in VB6.

Could anyone help me out in any way with doing a DNS lookup from VB6, specifying the servername to use?

A full working solution would of course be nice, but I’m willing to work: just point me in the right direction.

UPDATE: For some odd reason it didn’t click that DNSQuery was a Windows API call. It just didn’t sound like one. I certainly would have been able to make more headway on the problem if I’d gathered that one tiny detail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:22:23+00:00Added an answer on May 13, 2026 at 7:22 pm

    Try this:

    Option Explicit
    
    Private Declare Function DnsQuery Lib "dnsapi" Alias "DnsQuery_A" (ByVal strname As String, ByVal wType As Integer, ByVal fOptions As Long, ByVal pServers As Long, ppQueryResultsSet As Long, ByVal pReserved As Long) As Long
    Private Declare Function DnsRecordListFree Lib "dnsapi" (ByVal pDnsRecord As Long, ByVal FreeType As Long) As Long
    Private Declare Function lstrlen Lib "kernel32" (ByVal straddress As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, ByVal Source As Long, ByVal Length As Long)
    Private Declare Function inet_ntoa Lib "ws2_32.dll" (ByVal pIP As Long) As Long
    Private Declare Function inet_addr Lib "ws2_32.dll" (ByVal sAddr As String) As Long
    
    Private Const DnsFreeRecordList         As Long = 1
    Private Const DNS_TYPE_A                As Long = &H1
    Private Const DNS_QUERY_BYPASS_CACHE    As Long = &H8
    
    Private Type VBDnsRecord
        pNext           As Long
        pName           As Long
        wType           As Integer
        wDataLength     As Integer
        flags           As Long
        dwTel           As Long
        dwReserved      As Long
        prt             As Long
        others(35)      As Byte
    End Type
    
    Private Sub Command1_Click()
        MsgBox Resolve("google.com", "208.67.222.222")
    End Sub
    
    Private Function Resolve(sAddr As String, Optional sDnsServers As String) As String
        Dim pRecord     As Long
        Dim pNext       As Long
        Dim uRecord     As VBDnsRecord
        Dim lPtr        As Long
        Dim vSplit      As Variant
        Dim laServers() As Long
        Dim pServers    As Long
        Dim sName       As String
    
        If LenB(sDnsServers) <> 0 Then
            vSplit = Split(sDnsServers)
            ReDim laServers(0 To UBound(vSplit) + 1)
            laServers(0) = UBound(laServers)
            For lPtr = 0 To UBound(vSplit)
                laServers(lPtr + 1) = inet_addr(vSplit(lPtr))
            Next
            pServers = VarPtr(laServers(0))
        End If
        If DnsQuery(sAddr, DNS_TYPE_A, DNS_QUERY_BYPASS_CACHE, pServers, pRecord, 0) = 0 Then
            pNext = pRecord
            Do While pNext <> 0
                Call CopyMemory(uRecord, pNext, Len(uRecord))
                If uRecord.wType = DNS_TYPE_A Then
                    lPtr = inet_ntoa(uRecord.prt)
                    sName = String(lstrlen(lPtr), 0)
                    Call CopyMemory(ByVal sName, lPtr, Len(sName))
                    If LenB(Resolve) <> 0 Then
                        Resolve = Resolve & " "
                    End If
                    Resolve = Resolve & sName
                End If
                pNext = uRecord.pNext
            Loop
            Call DnsRecordListFree(pRecord, DnsFreeRecordList)
        End If
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.