Announcement

Collapse
No announcement yet.

Translate a host name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Translate a host name

    I want to get the ip host from a other DNS Server I know the PB is this

    HOST ADDR "localhost"

    But what I want to do is something like this

    nslookup bizp002.patrol.local 129.161.141.5

    So how do I get HOST ADDR "localhost" to point to a other DNS server?
    Inv. Mark Nelson

  • #2
    Originally posted by Mark A Nelson View Post
    So how do I get HOST ADDR "localhost" to point to a other DNS server?
    Are you attempting to determine the DNS server address, or have I missed the point completely?

    Comment


    • #3
      HOST ADDR "bizp002.patrol.local" TO ip&

      HOSTS file on the PC is always checked first before requesting from DNS server if not found in HOSTS. "localhost" is in HOSTS file.

      When you ask for something not in HOSTS file, request will go DNS server in IP settings (same place where gateway and subnet mask are set). If you're using DHCP, then DNS server, gateway and mask are sent to the PC along with the new IP number.
      Dale

      Comment


      • #4
        If I understand correctly, what you're asking about is how to resolve a hostname using a specific nameserver, rather than using whatever the default nameserver is configured on the system. If that's the case, you'd need to either implement the DNS protocol yourself in your program, use a library (WinDNS or SocketTools, for example), or shell out to \windows\system32\nslookup.exe and parse the output. For more information on using the WinDNS API, take a look at the MSDN documentation online, specifically the DnsQuery function:

        http://msdn2.microsoft.com/en-us/lib...58(VS.85).aspx

        There's also been some code posted for performing basic A and MX record lookups purely in PB code:

        http://www.powerbasic.com/support/pb...ad.php?t=24230

        For something a bit simpler, SocketTools includes a DNS API that can be used to do low level queries against specific nameservers. Here's an example of how that would look:

        Code:
        #Compile Exe
        #Dim All
        #Include "WIN32API.INC"
        #Include "CSTOOLS5.INC"
        
        Function PBMain () As Long
            Local hClient As Dword
            Local szHostName As Asciiz * 128
            Local szAddress As Asciiz * 64
            Local nResult As Integer
            
            ' Initialize the SocketTools DNS API
            DnsInitialize($CSTOOLS5_LICENSE_KEY, %NULL)
        
            ' Create a client session handle with the default timeout
            ' and retry period for querying the nameservers
            hClient = DnsCreateHandle(%DNS_TIMEOUT, %DNS_RETRIES, 0)
        
            If hClient <> %INVALID_CLIENT Then
                '
                ' Specify the nameservers that you want to use, in this case
                ' it's the free public nameservers offered by resolvingnameserver.com
                ' http://www.resolvingnameserver.com/freerns.html
                '
                ' Whatever nameservers you specify, you should make sure that
                ' you have permission; for example, you shouldn't use the nameservers
                ' of an ISP unless you're a customer or have explicit permission
                '
                DnsRegisterServer(hClient, 0, "205.234.170.215", %DNS_PORT_DEFAULT)
                DnsRegisterServer(hClient, 1, "205.234.170.217", %DNS_PORT_DEFAULT)
        
                ' Resolve the hostname "www.catalyst.com" into an IP address and
                ' return that as a string value
                nResult = DnsGetHostAddress(hClient, "www.catalyst.com", szAddress, 64)
                If nResult <> %DNS_ERROR Then
                    MsgBox "The IP address for this system is " + szAddress
                End If
        
                ' Resolve the IP address back into a hostname using a reverse
                ' lookup; this will give you the actual hostname for a given
                ' system, rather than any aliases for that system
                nResult = DnsGetHostName(hClient, szAddress, szHostName, 128)
                If nResult <> %DNS_ERROR Then
                    MsgBox "The actual hostname for this system is " + szHostName
                End If
                
                ' Close the session handle
                DnsCloseHandle(hClient)
            End If
            
            ' Uninitialize the DNS API
            DnsUninitialize()
        End Function
        Mike Stefanik
        sockettools.com

        Comment

        Working...
        X