Skip to content

Commit

Permalink
remote start
Browse files Browse the repository at this point in the history
  • Loading branch information
injetlee committed Oct 24, 2018
1 parent e9ba0df commit 2eec9cc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Python 黑魔法/Python 远程开机.py
Original file line number Diff line number Diff line change
@@ -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)

This comment has been minimized.

Copy link
@HoangHaiNam1234

HoangHaiNam1234 Jun 10, 2022

def for p is 0

This comment has been minimized.

Copy link
@Seadam

Seadam via email Jun 10, 2022

This comment has been minimized.

Copy link
@luhengchang

luhengchang via email Jun 10, 2022

# 通过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)
7 changes: 7 additions & 0 deletions Python 黑魔法/README.MD
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2eec9cc

Please sign in to comment.