convert hex IP address into hostname

You could hexify D83ACD2E, pack it into a (Network byte order!) 32-bit integer, then print the (unsigned!) character components of that integer joined by dots. (This is also possible if somewhat more verbose in assembly.)

$ perl -e 'printf "%v*d\n", ".", pack "N", hex shift' D83ACD2E
216.58.205.46
$ 

With fewer complications the decimal flag to gethostip gives that value directly, which then can be fed to host or nslookup or getent hosts

$ gethostip -d google.com
172.217.3.206
$ host `gethostip -d google.com`
206.3.217.172.in-addr.arpa domain name pointer sea15s12-in-f206.1e100.net.
206.3.217.172.in-addr.arpa domain name pointer sea15s12-in-f14.1e100.net.
$ getent hosts `gethostip -d google.com`
172.217.3.206   sea15s12-in-f206.1e100.net
$ 

that's the DNS PTR record associated with the given IP address, which may or may not be set, or may or may not be the hostname you are looking for.

Or if you search around with apt-file

$ sudo apt-file search getaddrinfo | grep 'getaddrinfo$'
gnulib: /usr/share/gnulib/modules/getaddrinfo
libruli-bin: /usr/bin/ruli-getaddrinfo
libsocket-getaddrinfo-perl: /usr/bin/socket_getaddrinfo
$ sudo apt-file search getnameinfo | grep 'getnameinfo$'
libsocket-getaddrinfo-perl: /usr/bin/socket_getnameinfo
$ sudo apt-get install libsocket-getaddrinfo-perl
...

but that version does not appear to support your notation:

$ socket_getnameinfo D83ACD4E
Unrecognised address or port format - Name or service not known
$ 

but does if the conventional 0x for hex prefix is used

$ socket_getnameinfo 0xD83ACD4E
Resolved address '0xD83ACD4E'

  mil04s25-in-f78.1e100.net
$ 

(according to the man page Debian did rename the program, which I now recall LeoNerd mentioning on IRC a while ago...)

If you're dead set on accepting D83ACD4E this can be done with the above hex to numify that value, packing it, and punching that blindly through Socket module functions. But this really should be a script with error checking, input validation, tests, etc

$ perl -MSocket=:addrinfo,pack_sockaddr_in \
  -E '($e,$h)=getnameinfo pack_sockaddr_in(0, pack("N", hex shift));' \
  -E 'say $h' D83ACD2E
mil04s24-in-f46.1e100.net
$ 

You may be able to use glibc's getent here:

$ getent ahostsv4 0xD83ACD2E | { read ip rest && getent hosts "$ip"; }
216.58.205.46   mil04s24-in-f46.1e100.net

Another perl approach:

$ perl -MSocket -le '($n)=gethostbyaddr(inet_aton("0xD83ACD2E"), AF_INET); print $n'
mil04s24-in-f46.1e100.net

Tags:

Hex

Ip

Tftp