SEARCH

The How-To Geek Forums Have Migrated to Discourse

How-To Geek Forums / Linux

Capture packages from router to do wake on lan

(4 posts)
  • Started 1 year ago by franmf
  • Latest reply from franmf
  • Topic Viewed 998 times

franmf
Posts: 4

Hi everybody. I'm working in my final degree project, and I've been told to do the next:

I need the router to do an automatic WAKE ON LAN when a service is needed from a host and it's asleep.

The normal sequence would be:
1-I need to access to a service from PC1 (i.g. desktop remote control)
2-I know PC1 is asleep, so I make first and automatic WOL with the magic package.
3-I wait PC1 to boot up
4-I access desktop remote control.

and I'd like to be like this:
1-I need to access to a service from PC1 (i.g. desktop remote control)
2-The routers detects itself that PC1 is asleep (lets say there is a table like (MAC address, IP address, state -wake up, asleep, time_to_wake_up)
3-If PC1 is asleep, the routers itself wakes it up and waits time_to_wake_up seconds.
4-the router sends the access to the service.

I'm working in ubuntu with openwrt backfire version. I've downloaded "knock" and "wol" packages, and I've been looking in "iptables" package, but I still don't know what can I do to reach that target. I need some help.

Thank you very much.

Posted 1 year ago
Top
 
franmf
Posts: 4

any idea?

Posted 1 year ago
Top
 
ispalten
ispalten
Posts: 6259

If from an external site on the Internet, you probably have to set routing or passthru for the packet on your router. Some routers will 'throw away' unsolicited packets they get from the web. Easiest way if ONLY one PC needs to get the WOL packet is place that PC on the 'demilitarized zone' of the router.

Irv S.

Posted 1 year ago
Top
 
franmf
Posts: 4

hi again. I've wrote the next code, am I in the correct line?
I'm writing those lines in the sniff method in the knockd.c class from knock package. There is the place where all frames are sniffed and controlled.

//1-Set IP's and Mac's array
//2-get Ip dest from package
//3-See if I get a HIT in the asleep list (ip and mac arrays)
//4-if HIT, I execute command line(etherwake mac)


int size;
char ip[size][16];
ip[0]="xxx.xxx.xxx.xxx"; //e.g.
ip[1]="yyy.yyy.yyy.yyy"; //e.g.

char mac[size][17];
mac[0]="aa:bb:cc:dd:ee:ff"; //e.g.
mac[1]="11:22:33:44:55:66"; //e.g.

if(ip->protocol == IPPROTO_TCP || ip->protocol == IPPROTO_UDP){
inaddr.s_addr = ip->daddr;
strncpy(dstIP, inet_ntoa(inaddr), sizeof(dstIP)-1);
dstIP[sizeof(dstIP)-1] = ''; //Here I get the IP dest

for(int i = 0; i < size; i++) {
if(strcmp(ip[i],dstIP)){ //If HIT, means IP Dest is a asleep one.
system("etherwake " + mac[i]);
}
}
}

Posted 1 year ago
Top
 



Topic Closed

This topic has been closed to new replies.

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!