#!/usr/bin/env python
# wol.py
import socket
import struct
def wake_on_lan(macaddress):
""" Switches on remote computers using WOL. """
# Check macaddress format and try to compensate.
if len(macaddress) == 12:
pass
elif len(macaddress) == 12 + 5:
sep = macaddress[2]
macaddress = macaddress.replace(sep, '')
else:
raise ValueError('Incorrect MAC address format')
# Pad the synchronization stream.
data = ''.join(['FFFFFFFFFFFF', macaddress * 20])
send_data = ''
# Split up the hex values and pack.
for i in range(0, len(data), 2):
send_data = ''.join([send_data,
struct.pack('B', int(data[i: i + 2], 16))])
# Broadcast it to the LAN.
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(send_data, ('<broadcast>', 7))
if __name__ == '__main__':
# Use macaddresses with any seperators.
wake_on_lan('0F:0F:DF:0F:BF:EF')
wake_on_lan('0F-0F-DF-0F-BF-EF')
# or without any seperators.
wake_on_lan('0F0FDF0FBFEF')
原文:http://code.activestate.com/recipes/358449-wake-on-lan/
PS:魔术包的格式,包含有连续6个字节的“FF”和连续重复16次的MAC地址。你可以在任何协议的数据包(如在TCP/IP、IPX包)中填上 "FFFFFFFFFFFF"+连续重复16次的MAC地址,就可利用该协议作出一个使用该协议的MagicPacket。只要NIC检测到数据包中任何地方有这样的片段,便会将计算机唤醒。
分享到:
相关推荐
recipe-scrapers, 用于抓取配方数据的python 包 配方刮削器 一个简单的网络擦洗工具,用于我在我的工程中使用的菜谱工具,这是一个。 不支持 python 2. pip install git+git://github.com/hhursev/recipe-scraper
Finding a File on the Python Search Path Recipe 2.21. Dynamically Changing the PythonSearch Path Recipe 2.22. Computing the Relative Path from One Directory to Another Recipe 2.23. Reading an ...
资源分类:Python库 所属语言:Python 资源全名:recipe-0.30.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:djc.recipe2-2.1.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:whtc.recipe.configmanager-1.1.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:recipe-0.12.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python库。 资源全名:recipe_scrapers-10.1.0.tar.gz
python库,解压后可用。 资源全名:as.recipe.filetemplate-2.2.0-py2.7.egg
资源分类:Python库 所属语言:Python 资源全名:recipe-0.11.0rc1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Each chapter is devoted to a particular kind of recipe, such as algorithms, text processing, databases, and so on. The 1st edition had 17 chapters. There have been improvements to Python, both ...
This cookbook is written as a collection of code recipes containing step-by-step directions on how to install or build different types of Python test tools to solve different problems. Each recipe ...
Code supporting the CVPR 2017 paper "Learning Cross-modal Embeddings for Cooking Recipes and Food Images
Over 80 object-oriented recipes to help you create mind-blowing GUIs in Python ... At the same time, most of the recipes build on each other to create an entire, real-life GUI application.
python库。 资源全名:appfy.recipe.gae-0.7.1.zip
python库。资源全名:recipe_searchers-0.0.6-py3-none-any.whl
python库。 资源全名:git-recipe-0.2.7.tar.gz
资源分类:Python库 所属语言:Python 资源全名:recipe_scrapers_ap_fork-13.3.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:collective.recipe.plonesite-1.9.5.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:collective.recipe.bluebream-0.1.0.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059