Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-29-2015, 04:27 PM   #1
LQ Newbie
Registered: Nov 2015
Location: Germany
Distribution: Ubuntu / Lubuntu / Busybox
Posts: 2

Rep: Reputation: Disabled
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:

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
Old 12-01-2015, 01:25 AM   #2
Senior Member
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,276

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

You can run tcpdump like this:
tcpdump -i ethX -nn dst host
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.
Old 12-01-2015, 10:38 AM   #3
LQ Newbie
Registered: Nov 2015
Location: Germany
Distribution: Ubuntu / Lubuntu / Busybox
Posts: 2

Original Poster
Rep: Reputation: Disabled
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:

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 > /dev/null); then
echo `date`" Registered action on port X." >> /var/media/ftp/uStor01/checkport.log
ether-wake -b
sleep 60
Does this make senes?
And how exactly would I save this in order for it to be a functioning shell command?



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Tcpdump/ngrep sniff packet network command lines Tonyyyp Linux - Newbie 2 06-22-2011 01:53 PM
WOL - Send Magic Packet GanX Linux - Newbie 19 04-04-2011 09:41 AM
Problem sending wol packet ubuntuv Linux - Networking 1 09-10-2010 07:05 PM
7.10 Server wol (wake-on-lan) via ARP (no magic packet), help? Elohist Linux - Networking 0 01-21-2008 12:02 AM > Forums > Linux Forums > Linux - Newbie

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

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