Sample code for 30+ languages & platforms
PureBasic

Resolve a Hostname to an IP Address

See more Socket/SSL/TLS Examples

Demonstrates Socket.DnsLookup, which resolves a hostname and returns one numeric IP address.

Background. A maxWaitMs of 0 waits indefinitely; a positive value bounds the wait. Resolved results may be served from Chilkat's process-wide DNS cache.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkSocket.pb"

Procedure ChilkatExample()

    socket.i = CkSocket::ckCreate()
    If socket.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Resolve a hostname to a numeric IP address, waiting up to 5 seconds.
    ipAddress.s = CkSocket::ckDnsLookup(socket,"example.com",5000)
    If CkSocket::ckLastMethodSuccess(socket) = 0
        Debug CkSocket::ckLastErrorText(socket)
        CkSocket::ckDispose(socket)
        ProcedureReturn
    EndIf

    Debug "Resolved IP address: " + ipAddress


    CkSocket::ckDispose(socket)


    ProcedureReturn
EndProcedure