1 |
#!/usr/bin/perl |
2 |
|
3 |
# IP address resolver for Boa |
4 |
|
5 |
# If you want an "in place" change to the log file, |
6 |
# change the first line to |
7 |
#!/usr/local/bin/perl -i.bak |
8 |
# Otherwise, send the output of this program wherever you want: |
9 |
# resolver.pl access_log >access_log_resolved |
10 |
|
11 |
$AF_INET = 2; |
12 |
|
13 |
while(<>) { |
14 |
next unless (($ip, $rest) = /([\d\.]+) (.*)/o); |
15 |
|
16 |
if(!$hosts{$ip}) { |
17 |
$packed_ip = pack('C4', split(/\./, $ip)); |
18 |
$host = (gethostbyaddr($packed_ip, $AF_INET))[0]; |
19 |
$hosts{$ip} = ($host ? $host : $ip); |
20 |
} |
21 |
|
22 |
print "$hosts{$ip} $rest\n"; |
23 |
} |
24 |
|