xuhaohunter

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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  阅读(355)  评论(0编辑  收藏  举报