android firmware 利用UDP socket发送Magic Packet--python版本

android firmware 利用UDP socket发送Magic Packet--python版本

 

#!/usr/bin/python

import sys, time
from struct import *
from socket import *  

src_ip = '192.168.1.108'
dst_ip = '192.168.1.105'
port = 2014

try:
#   s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
    s = socket(AF_INET, SOCK_DGRAM)  
    s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)  
    s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)  
    s.bind((src_ip, port))
except socket.error, msg:
    print 'Socket could not be created. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
    sys.exit()


#wakeup pattern
ff_pattern = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
wakee_mac = [0x00, 0x03, 0x7F, 0x33, 0x11, 0x22]
secure_on = [0x08, 0x00, 0x27, 0x1d, 0x32, 0x51]
wakeup_identification = 'SECWOW'
reserve = [0x00, 0x00, 0x00, 0x00]
app_id = 0 #can be 0/1/2
passwd = '123456789' #len = 0~16
passwd_len = len(passwd)


#pack_format = '8sBBBBBBBB' + str(passwd_len) + 's' + 'x' * (16 - passwd_len)
pack_format = 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB6sBBBBBB' + str(passwd_len) + 's' + 'x' * (passwd_len)
 
user_data = pack(pack_format, ff_pattern[0], ff_pattern[1], ff_pattern[2], ff_pattern[3], ff_pattern[4], ff_pattern[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		wakee_mac[0], wakee_mac[1], wakee_mac[2], wakee_mac[3], wakee_mac[4], wakee_mac[5], \
		secure_on[0], secure_on[1], secure_on[2], secure_on[3], secure_on[4], secure_on[5], \
		wakeup_identification, \
		reserve[0], reserve[1], reserve[2], reserve[3], \
		app_id, passwd_len, passwd)


while 1:
	s.sendto(user_data, (dst_ip, port))
	time.sleep(5)

 

posted on 2016-07-04 16:52 xuhaohunter 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/xuhaohunter/p/5640984.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值