2011-03-18

Get IP via hostname or hostname via IP in PL/SQL

Sometimes you need to find out in PL/SQL the IP address of a hostname or more frequently the hostname from the IP address (as nslookup does), for instance to check where a web request is from.

Oracle has the package utl_inaddr that allows us to solve that problem.


Let's see some use examples:


select utl_inaddr.get_host_address('www.google.com') as ipaddress from dual;

IPADDRESS
------------------------------
209.85.129.147


select utl_inaddr.get_host_name('209.85.129.147') as hostname from dual;


HOSTNAME
-----------------------------
fk-in-f147.google.com


Of course the function utl_inaddr.get_host_address will give one of the answering IP address and that IP address can have a specific hostname.


Versão Portuguesa deste post disponível

No comments:

Post a Comment

Os comentários são moderados.
The comments are moderated.