convert LAN IP address to Host Name when I give cmd tail -f /var/log/squid/access.log
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
convert LAN IP address to Host Name when I give cmd tail -f /var/log/squid/access.log
I am using Fedora 4. I have configured squid as a proxy server for my official LAN. When I monitor the log I want the local IP's hostname when it sends http request to proxy server.How can I convert LAN IP address to Host Name when I give command tail -f /var/log/squid/access.log?
use strict;
use IO::File;
use Fcntl qw(:seek);
use Socket;
my $fh = IO::File->new('/var/log/squid/access.log');
my $line;
while(1) {
$fh->seek(0,1);
$line = $fh->getline();
if ($line) {
chomp $line;
my (@fields) = split(' ', $line);
my $addr = $fields[2];
my $name = gethostbyaddr(inet_aton($addr), AF_INET);
if ($name) {
$fields[2] = $name;
}
print join(' ', @fields), "\n";
}
else {
sleep 1;
}
}
I've added sleep call because the previous version eats 100% CPU
Thank you very much for your quick reply. But there are too many things in /usr/lib/perl. How and where should I insert this code? For your kind information I am very new linux environment.
yeh...., I have done the job, at last. Thanks a lot. It shows the hostname instead of IP. But when I put the command perl squid-tail.pl, it executes the whole access.log file. Is it possible to show only desired part or latest part of access.log.
guys,
Thanks for code. That is fantastic. But here are the two things...
How much resource it will actually take?? I have a Local DNS and resolving is damn fast infact. using this, using Vyatta Squid and SARG, i can track my hosts (300 of them) easily. But again, as it is a continuously running script with a forever while loop, how can i put it integrated so that it will do the lookup on a controlled manner, like a cron job, as first it will be executed then the "sarg-reports daily" in hour basis. This way, I dont want to keep it running for ever and to run it just when i'm making the log analysis.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.