File: resolver.pl

package info (click to toggle)
boa 0.93.14.1-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 428 kB
  • ctags: 389
  • sloc: ansic: 3,014; yacc: 210; makefile: 122; lex: 108; perl: 49; sh: 30
file content (24 lines) | stat: -rwxr-xr-x 574 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/local/bin/perl

# IP address resolver for Boa

# If you want an "in place" change to the log file,
# change the first line to
#!/usr/local/bin/perl -i.bak
# Otherwise, send the output of this program wherever you want:
#  resolver.pl access_log >access_log_resolved

$AF_INET = 2;

while(<>) {
    next unless (($ip, $rest) = /([\d\.]+) (.*)/o);

    if(!$hosts{$ip}) {
        $packed_ip = pack('C4', split(/\./, $ip));
        $host = (gethostbyaddr($packed_ip, $AF_INET))[0];
        $hosts{$ip} = ($host ? $host : $ip);
    }

    print "$hosts{$ip} $rest\n";
}