LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-29-2015, 04:27 PM   #1
tb2668
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:

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
 
Old 12-01-2015, 01:25 AM   #2
berndbausch
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:
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.
 
Old 12-01-2015, 10:38 AM   #3
tb2668
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:

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
 
  


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:53 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration