Hamster-Scripts: Functions (Hamster): DNS

DNS

HamDnsLookupHostAddr( <hostname> )

Looks up the IP number of given <hostname>.

Note: This command makes use of an internal cache (see HamDnsCachePurge below).

Returns: String with IP, "0.0.0.0" if not found.

print( HamDnsLookupHostAddr( "localhost" ) )

HamDnsLookupHostAddrList( <hostname-list>, <result-list> )

Looks up the IP numbers of the given host names (<hostname-list>) and returns the result in the second list (<result-list>).

Note: This command makes use of an internal cache (see HamDnsCachePurge below).

Returns: true if given lists are valid, false otherwise .

var( $i, $Names, $Addrs )

$Names = ListAlloc
$Addrs = ListAlloc

ListAdd( $Names, "localhost" )
ListAdd( $Names, "example.com" )
ListAdd( $Names, "example.invalid" )

HamDnsLookupHostAddrList( $Names, $Addrs )

for( $i, 0, ListCount( $Names ) - 1 )
   print( ListGet( $Names, $i ), " -> ", ListGet( $Addrs, $i ) )
endfor

ListFree( $Addrs )
ListFree( $Names )

HamDnsCachePurge( <minutes> )

Removes all entries from the internal lookup cache that are older than the given number of <minutes> and also saves the cache to a file.

Returns: Number of remaining entries in cache.

if( GlobalOnce( "purge cache", 60 ) ) # check once per hour
   HamDnsCachePurge( 24 * 60 ) # keep entries for one day
endif

[www.elbiah.de Hamster Playground Documentation]