From 2eec9cc964a3f4b135451d55d6aa1f54ed0a8fc6 Mon Sep 17 00:00:00 2001 From: injetlee Date: Wed, 24 Oct 2018 22:41:44 +0800 Subject: [PATCH] remote start --- Python 黑魔法/Python 远程开机.py | 28 +++++++++++++++++++++++++ Python 黑魔法/README.MD | 7 +++++++ 2 files changed, 35 insertions(+) create mode 100644 Python 黑魔法/Python 远程开机.py create mode 100644 Python 黑魔法/README.MD diff --git a/Python 黑魔法/Python 远程开机.py b/Python 黑魔法/Python 远程开机.py new file mode 100644 index 0000000..1b23c16 --- /dev/null +++ b/Python 黑魔法/Python 远程开机.py @@ -0,0 +1,28 @@ +def wake_up(request, mac='DC-4A-3E-78-3E-0A'): + MAC = mac + BROADCAST = "192.168.0.255" + if len(MAC) != 17: + raise ValueError("MAC address should be set as form 'XX-XX-XX-XX-XX-XX'") + mac_address = MAC.replace("-", '') + data = ''.join(['FFFFFFFFFFFF', mac_address * 20]) # 构造原始数据格式 + send_data = b'' + + # 把原始数据转换为16进制字节数组, + for i in range(0, len(data), 2): + send_data = b''.join([send_data, struct.pack('B', int(data[i: i + 2], 16))]) + print(send_data) + + # 通过socket广播出去,为避免失败,间隔广播三次 + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + sock.sendto(send_data, (BROADCAST, 7)) + time.sleep(1) + sock.sendto(send_data, (BROADCAST, 7)) + time.sleep(1) + sock.sendto(send_data, (BROADCAST, 7)) + return HttpResponse() + print("Done") + except Exception as e: + return HttpResponse() + print(e) \ No newline at end of file diff --git a/Python 黑魔法/README.MD b/Python 黑魔法/README.MD new file mode 100644 index 0000000..99d1cf3 --- /dev/null +++ b/Python 黑魔法/README.MD @@ -0,0 +1,7 @@ +# 代码详细说明请看文章 + +[Python 爬虫入门(一)——爬取糗事百科](https://mp.weixin.qq.com/s/ApnEy6NWS2f-DqIIrhHzGw) + +[Python 爬虫入门(二)——爬取妹子图](https://mp.weixin.qq.com/s/4TZHgoE_yqeDha17f3Tbew) + +[Python 爬虫——Python 岗位分析报告](https://mp.weixin.qq.com/s/8wAHBPnQMbcrP9La7WZiJA) \ No newline at end of file