perl gethostbyaddress

pushVTEC

Senior member
Aug 30, 2003
265
0
0
So i'm parsing an access log so I have all the ips. I try to do gethostbyaddress($ip, AF_INET) and it doesn't return anything. What am I doing wrong? I've looked at examples it looks like I'm doing it right. All I want is the hostname to return.
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
$ip must be the integer equivalent of the IP address.

You need to add

$ip = inet_aton("1.1.1.1");
 

pushVTEC

Senior member
Aug 30, 2003
265
0
0
I have

$key = inet_aton($key);
$b = gethostbyaddr($key, AF_INET);
print $b;

and it doesn't work, what am i doing wrong?
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
This works for me:

#!/usr/bin/perl
use Socket;
my $ip = inet_aton("66.51.174.166");
my $name = gethostbyaddr($ip, AF_INET);
print ("name = $name\n");
 

pushVTEC

Senior member
Aug 30, 2003
265
0
0
ah do I need that use socket part? And I put that at the top near #!/usr/bin/perl right?