Last active
          December 20, 2015 18:49 
        
      - 
      
 - 
        
Save b4hand/6178774 to your computer and use it in GitHub Desktop.  
    Do an IP to name resolution from the command line
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | perl -e 'use Socket qw(getnameinfo inet_aton pack_sockaddr_in NI_NUMERICSERV); my $ip = inet_aton($ARGV[0]); my $addr = pack_sockaddr_in(80, $ip); my ($err, $hostname) = getnameinfo($addr, NI_NUMERICSERV); print "$hostname\n"' | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
This one-liner expects a single IP address argument to be passed on the command line.
The advantage to this one liner is that it only uses Socket which is a standard library module of Perl, and thus works on every machine that has Perl installed, which is even more common than having the bind libraries.
You may also be interested in name_to_ip which does a forward DNS lookup in a one-liner.