LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to listen for a specific ping packet and take an action when it is received (https://www.linuxquestions.org/questions/linux-networking-3/how-to-listen-for-a-specific-ping-packet-and-take-an-action-when-it-is-received-4175490153/)

paicito 01-04-2014 05:41 PM

How to listen for a specific ping packet and take an action when it is received
 
Hi all,

Here is what I am trying to accomplish.
I have two servers, the first one (server A) is always up and the other (server B) only when needed.
The goal is to trigger an action on server A after receiving a specific echo packet from server B:
1) server B comes online
2_a) server B sends a specific ping packet (with a modified size and/or content) to server A
2_b) server A is listening for a specific ping packet (this is the step I am asking your help for)
3) trigger an action on server A when it gets the specific ping packet.

I would like to do it in bash but any other language (perl, python, C, etc.) is OK.

Thanks for your input,
paicito

zhjim 01-06-2014 07:35 AM

Some thoughts on this.

use a raw icmp socket server programm. Checkout http://beej.us/guide/bgnet/
use iptables with -m string and -j NFLOG and an nflog programm that runs your programm.
use iptables and -m recent and parse the recent files in /proc and run command. Could also -j SET and search those files.
use ssh and key login from server b to just run a command on server A.
Or write a costum server/client application.

jefro 01-06-2014 09:21 AM

Wonder if a different type of packet would be better??? Ping is a poor choice since it can be blocked by too many things.

paicito 01-06-2014 09:47 AM

Thanks for your input guys, I finally wrote a simple server-client communication, using a UDP port.

Thanks again!

TB0ne 01-06-2014 11:08 AM

Quote:

Originally Posted by paicito (Post 5092869)
Thanks for your input guys, I finally wrote a simple server-client communication, using a UDP port.

Thanks again!

Glad you got it going...but you really should check into portknocking, since that's exactly what you're describing:
http://www.portknocking.org/

There are MANY already-existing scripts (perl and bash), that do this, and the knockd daemon is avaiable to you.


All times are GMT -5. The time now is 12:03 AM.