KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Reverse DNS Lookup via HTTP GET using dns-api.org
PRODUCT: 4D | VERSION: 15.3 | PLATFORM: Mac & Win
Published On: November 15, 2016

Here is a nifty trick to perform a Reverse DNS Lookup on an IP Address that utilizes a web based REST API.

This approach utilizes HTTP GET to do the DNS Lookup via a REST API provided by dns-api.org:

C_TEXT($0)
C_TEXT($1;$url_t;$response_t;$thisDNS_t)
C_LONGINT($httpStatusCode_li;$a)
ARRAY OBJECT($response_oba;0)
If (Count parameters=2)
   $url_t:="https://dns-api.org/ptr/"+$1
   $httpStatusCode_li:=HTTP Get($url_t;$response_t)
   If ($httpStatusCode_li=200)
      If (Substring($response_t;1;1)="[")
         JSON PARSE ARRAY($response_t;$response_oba)
         If (Type($2->)=Text array)
            For ($a;1;Size of array($response_oba))
               $thisDNS_t:=OB Get($response_oba{$a};"value";Is text)
               If (Substring($thisDNS_t;Length($thisDNS_t);1)=".")
                   // strip trailing dot
                  $thisDNS_t:=Substring($thisDNS_t;1;Length($thisDNS_t)-1)
               End if
               APPEND TO ARRAY($2->;$thisDNS_t)
            End for
         End if
      End if
   End if
End if


If the method above is saved as UTIL_ReverseDNSLookup then it could be used like this:

ARRAY TEXT(domains_at;0)
UTIL_ReverseDNSLookup ("123.45.67.89" ;->domains_at)


The code above will populate the domains_at text array with any PTR records found for 123.45.67.89