Google
 
loading...

I posted an article about WOL over Internet, it referred a python script which send UDP WOL Magic-package over UDP. Recent the script has been updated, the reason is my office firewall block any UDP package except for DNS query, even when an non-DNS UDP package was tried to send through port 53, the firewall block it.

what I need to do is encapsulate a Magic-package into a fake DNS query, indeed my strategy is pack it into query domain name part. The package head is easy to construct. So the problem is how to pack the 102(6+6*16) bytes Magic-package.

----------------------------------------------------------------------------------------

If you can't understand the paragraph below, it's my fault, I can't explain it well. So don't read it again, goto code, everything is in code, and the python code is easy to understand.

----------------------------------------------------------------------------------------

The max length of a label in domain name is 63, which can contain first 6 '0xff' and 8 mac, (here 6+6*8=54 bytes is done). Then the first byte of remaining 48(102-54) bytes (also the first byte of 9th mac) is the length of the second label of domain name, so this byte value must between 1 and 63. if it's in this range(let's say it's 10), the next 10 bytes is the second label in domain name, (here 6+6*8+1+10=65 bytes is done), and the first byte value of remain 37 bytes must between 1 and 63 ..., etc. We can call "the first byte of remaining bytes" "key bytes". Let's repeat this process until all 102 bytes are consumed, if all key bytes are between 1 and 63, we can pack the Magic-package into a domain name part. If we got a key bytes which is not in the range before consuming all 102 bytes, we fails.

Notice, we can start from not only the first byte of remaining 48 bytes in first iteration of process, actually we can regard any byte of the 9th mac as the length of the second label, bytes before that key byte can be pack into first label, that's is the first label has length of 54+(number of byte in 9th mac before key byte). So we have 6 chance.

----------------------------------------------------------------------------------------



Tags: python | wol |