LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-28-2012, 12:42 AM   #1
systemlordanubis
Member
 
Registered: Jun 2010
Distribution: Debian, Ubuntu, Win
Posts: 143

Rep: Reputation: 16
Perl program to listen for incoming ICMP data


Hi All,

I'm needing to make a program that is able to listen for incoming ICMP packets and obtain the MAC address of the calling party (the calling party in this case will always be on the same subnet).

I know that IO::Socket::INET does have an option to listen for ICMP but it doesn't seem to work.

Does anyone know how I could get this sort of program running under perl?

Thanks
Anubis.
 
Old 02-28-2012, 04:09 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
I would add input iptable rule and parse log, eg
Code:
iptables -A INPUT  -p icmp -j LOG --log-prefix "PING: "
And for parsing, something like
Code:
#!/usr/bin/perl

open LOG, 'tail -f /var/log/messages |' or die $!;

while(<LOG>) {
    do {
        /MAC=.*:(..:..:..:..:..:..).*/;
        print "Mac address: $1\n";
   } if /^PING/;
}
close LOG;

Last edited by Cedrik; 02-28-2012 at 04:21 AM.
 
Old 02-28-2012, 09:33 PM   #3
systemlordanubis
Member
 
Registered: Jun 2010
Distribution: Debian, Ubuntu, Win
Posts: 143

Original Poster
Rep: Reputation: 16
Hi Cedrik,

Hmm, that's some very good food for thought, but I wonder how large the log might get considering that there could be quite a number of records to process...

Also, wouldn't the 'tail' eventually close though when the log switches to the next log file?

If I was able to get around a couple of these things, this could actually make some of my processing even easier, I was going to also need a service to listen to TCP/UDP for which I was using a IO::Socket but this could replace a lot of this heavy lifting.

Certainly food for thought.


On another note however and just out of curiosity, is it possible to make and ICMP listneing service?

Thanks
Anubis.
 
Old 02-29-2012, 04:04 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
You have also the possibility to capture network packets, see: Net::Pcap::Easy perl module

http://search.cpan.org/~jettero/Net-....4207/Easy.pod

(with ICMP filter examples)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tor: Leaks ICMP data? hydraMax Linux - Security 6 02-28-2012 03:17 PM
Perl - Check incoming ports from inside saeen Linux - Newbie 1 02-25-2012 11:27 AM
Incoming TCP listen port sycamorex Linux - Networking 5 05-15-2007 11:35 AM
saving incoming serial data to a file mssucks Linux - Networking 1 12-14-2001 10:56 AM
save incoming data to a file mssucks Linux - Newbie 1 12-14-2001 09:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration