码迷,mamicode.com
首页 > 其他好文 > 详细

蛋疼研究所的蓝牙签到

时间:2016-04-01 20:30:54      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:

最近整个研究所对实验室的人采取了手机蓝牙签到机制,每个人手机上需要安装一个app,然后手动点击签到和离开按钮,以此来统计每个人的每天工作时间,不得不说这是个反人类的设计,本着just hacking for fun的精神,arp嗅探了手机发出去的数据包,得知和服务端是通过TCP进行通信,同时也得到了数据包的格式,于是开工写脚本,实现自动签到。

代码如下,用PHP socket实现:

  1 <?php
  2 /**
  3  * 1.生成当前时间,判断该时间是处于上午,下午,晚上的哪个时间段
  4  *
  5  * 2.根据时间段的判断生成随机时间
  6  *
  7  * 3.封包发送签到数据
  8  *
  9  * 
 10  */
 11 //生成随机时间的函数
 12 date_default_timezone_set(‘Asia/Chongqing‘);
 13 function rand_time($start_time,$end_time){
 14 
 15     $start_time = strtotime($start_time);
 16     $end_time = strtotime($end_time);
 17     return date(‘Y-m-d H:i:s‘, mt_rand($start_time,$end_time));
 18 }
 19 $curTime=date("H:i:s");         //当前时间
 20 if($curTime>="06:00:00" &&$curTime<="09:30:59")
 21 {
 22     $startTime=date("Y-m-d")." 06:00:00";
 23     $endTime=date("Y-m-d")." 08:30:59";
 24     $signTime=rand_time($startTime,$endTime);
 25 }
 26 else if($curTime>="09:31:00" && $curTime<="12:30:59")
 27 {
 28     $startTime=date("Y-m-d")." 11:45:00";
 29     $endTime=date("Y-m-d")." 12:30:59";
 30     $signTime=rand_time($startTime,$endTime);
 31 }
 32 
 33 if($curTime>="13:30:00" && $curTime<="15:30:59")
 34 {
 35     $startTime=date("Y-m-d")." 13:30:00";
 36     $endTime=date("Y-m-d")." 14:30:59";
 37     $signTime=rand_time($startTime,$endTime);
 38 }
 39 else if($curTime>="15:31:00" && $curTime<="18:30:59")
 40 {
 41     $startTime=date("Y-m-d")." 17:45:00";
 42     $endTime=date("Y-m-d")." 18:30:59";
 43     $signTime=rand_time($startTime,$endTime);
 44 }
 45 if($curTime>="19:30:00" && $curTime<="21:00:59")
 46 {
 47     $startTime=date("Y-m-d")." 19:30:00";
 48     $endTime=date("Y-m-d")." 20:00:59";
 49     $signTime=rand_time($startTime,$endTime);
 50 }
 51 else if($curTime>="21:01:00" && $curTime<="23:00:59")
 52 {
 53     $startTime=date("Y-m-d")." 22:30:00";
 54     $endTime=date("Y-m-d")." 23:00:59";
 55     $signTime=rand_time($startTime,$endTime);
 56 }
 57 $ssid=rand(1,100);
 58 $ssid="-".$ssid;    //随机生成信号强度
 59 error_reporting(E_ALL);
 60 set_time_limit(0);
 61 echo "BlueTooth Sign\n";
 62 
 63 $port = 8***;  //此处打码
 64 $ip = "202.***.***.***";    //此处打码  
 65 $blueTooth=<<<blueToothInfo
 66 upload
 67 24:**:**:**:**:**
 68 $signTime
 69 10:**:**:**:**:**
 70 $ssid
 71 exit
 72 
 73 blueToothInfo;
 74 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 75 if ($socket < 0) {
 76     echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
 77 }else {
 78     echo "OK.\n";
 79 }
 80 
 81 echo "尝试连接 ‘$ip‘ 端口 ‘$port‘...\n";
 82 $result = socket_connect($socket, $ip, $port);
 83 if ($result < 0) {
 84     echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
 85 }else {
 86     echo "连接成功\n";
 87 }
 88 if(!socket_write($socket, $blueTooth, strlen($blueTooth))) {
 89     echo "socket_write() failed: reason: " . socket_strerror($socket) . "\n";
 90 }else {
 91     echo "数据发送成功\n";
 92     echo "发送的内容为:\n$blueTooth";
 93 }
 94 $out = socket_read($socket, 20);//读取服务器返回的内容,20字节
 95 if($out=="sbwzc\n")
 96 {
 97     die("设备未注册");
 98 }
 99 if($out=="wsmdsmj\n")
100 {
101     die("未扫描到扫描机,签到失败,请重构数据包");
102 }
103 if($out=="success\n")
104 {
105     echo "签到成功\n";
106 }
107 echo "正在关闭连接...\n";
108 socket_close($socket);
109 echo "关闭成功\n";
110 ?>
111     

 

蛋疼研究所的蓝牙签到

标签:

原文地址:http://www.cnblogs.com/debugzer0/p/5345914.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!