LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using tcpdump to check for network requests and sending wol magic packet. (https://www.linuxquestions.org/questions/linux-newbie-8/using-tcpdump-to-check-for-network-requests-and-sending-wol-magic-packet-4175560171/)

tb2668 11-29-2015 04:27 PM

Using tcpdump to check for network requests and sending wol magic packet.
 
Hey everyone,

I have been looking through the forum, but couldn't find a thread that would help me out. At least I didn't recognize it as such.

I got a Fritzbox router running linux and busybox. My goal is to have a program running doing the following:

Code:

IF "PC is running (ping?)"
  "do nothing"

ELSE tcpdump port ## and dst 192.168.###.### (check if a request is coming through port ## to my PC)

IF tcpdump port ## and dst 192.168.###.### == true (request incoming)

THEN ether-wake ##-##-##-##-##-##

THEN "restart loop"

So basically I want my router to listen to request coming through specific ports. If my PC is shout down and a request is detected, I want my router so send a wol magic packet to my PC.

The thing is, that I am really new to this topic and the amount of information out there is just overwhelming. I was looking through a lot of threads, but I am getting more lost the more i read.

So is this the right path? Can someone help me with the syntax? Or is there maybe a better solution to this?

Thanks people
tb2668

berndbausch 12-01-2015 01:25 AM

So you want to wake up your PC if any packet is sent to its IP address.

You can run tcpdump like this:
Code:

tcpdump -i ethX -nn dst host 192.168.123.45
and pipe the output to a script that triggers etherwake each time something comes in. The -nn option avoids converting host names and ports from numbers to names. ethX is the interface name of the port.

In parallel, a script based on ping that will start the above tcpdump if there is no reply, and kill it if there is a reply.

I wonder if there isn't a better solution. For example snort, the intrusion detection system, can be configured so that it triggers an action when a certain network pattern is detected. But perhaps it's overkill for your task, and I don't know if it can be installed on the Fritzbox.

A kind of much simplified snort would be ideal.

tb2668 12-01-2015 10:38 AM

Hey berndbausch,

thank you for your reply.

Yes, I want my PC to wake up if contacted from outside, but only through specific ports.
Lets say I want to access my data using FTP with my phone while I am not at home. Then the Fritzbox should detect that port 21 is being forwarded to my PC and send a magic packet, if the PC is in sleep mode.

So here is my attempt so far:

Code:

echo "Listening to port X for Host-IP X" >> /var/media/ftp/uStor01/checkport.log
while !(ping -c 1 -q "X" > /dev/null); do
if (tcpdump -i any -c 1 -nn port X dst 192.168.xxx.xxx > /dev/null); then
echo `date`" Registered action on port X." >> /var/media/ftp/uStor01/checkport.log
ether-wake -b 192.168.xxx.xxx
fi
sleep 60
done

Does this make senes?
And how exactly would I save this in order for it to be a functioning shell command?

Thanks


All times are GMT -5. The time now is 01:33 AM.