Sniffing for WOL packets on port 9

2.2k Views Asked by At

So I am using XBMC (a media center program) that has an Android app with a feature that allows you to send Wake on LAN "magic packets" to computers you have XBMC installed on. While this would be a great feature for me if I had a dedicated media PC that auto-ran XBMC on startup, I use it instead on my normal desktop PC.

What I would like to do is see if I can write a little listener script that would run on my PC that would listen for those magic packets sent over port 9 and just start the XBMC application.

Some of my friends say that you cannot listen on this port. The Google searches on "port 9", "wake on lan", and "simple TCP/IP" I've performed remain inconclusive as to weather or not this is possible.

2

There are 2 best solutions below

1
On

You should be able to do this on a Windows PC. However your program will not run on a *Nix style system without having superuser, or using a privilege escalator program like jsvc.

1
On

With Python and pcap (winpcap and pypcap http://code.google.com/p/pypcap/). Not very nice but works for me.

import os, pcap

pc = pcap.pcap()

pc.setfilter('udp port 9 and (udp[8:4] == 0xFFFFFFFF and udp[12:2] == 0xFFFF)')

for ts, pkt in pc:
    os.system(r'"C:\Program Files (x86)\XBMC\xbmc.exe"')