Repository navigation
Expand file tree
/
Copy pathsend_http_by_fopensocket.php
More file actions
90 lines (83 loc) · 2.28 KB
/
Copy pathsend_http_by_fopensocket.php
File metadata and controls
90 lines (83 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
class JsonRPC
{
private $host;
private $port;
private $conn;
public function __construct($host = '127.0.0.1', $port = '80')
{
$this->host=$host;
$this->port=$port;
}
protected function connect(){
$this->conn = fsockopen($this->host, $this->port, $errno, $errstr, 3);
if (!$this->conn) {
return false;
}
}
public function Call($url,$method, $params) {
$this->connect();
if (!$this->conn) {
return false;
}
$content['id']="0";
$content['jsonrpc']="2.0";
$content['method'] = $method;
$content['params']=$params;
$content=json_encode($content);
$contentlen=strlen((string)$content);
$head="POST {$url} HTTP/1.1"."\r\n";
// $content.='User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0'.PHP_EOL;
$head.='Accept: application/json'."\r\n";
$head.='Content-Type: application/json; charset=utf-8'."\r\n";
$head.='Content-Length: '.$contentlen."\r\n";
$head.='Connection:close'."\r\n\r\n";
$head.=(string)$content;
echo $head.PHP_EOL;
echo 'request:'.PHP_EOL;
$err = fwrite($this->conn, $head);
if ($err === false)
return false;
stream_set_timeout($this->conn, 0, 1);
$response='';
while(!feof($this->conn)){
$response.=fgets($this->conn,128);
}
$pos=strpos($response,"\r\n\r\n");
$response=substr($response,$pos+4);
return json_decode($response,true);
}
public function __destruct()
{
fclose($this->conn);
}
}
$count=20000;
$response=0;
$error=0;
$client = new JsonRPC("192.168.0.12", 80);
$data =array(
'ip'=>getIpSegement($i),
);
$params['data']=$data;
$method='method';
$r = $client->Call($url,$method,$params);
if($r['result']['info']=='accepted'){
$response++;
}else{
$error++;
}
$data=[];
$client = null;
echo '成功:'.$response.PHP_EOL;
echo '失败:'.$error.PHP_EOL;
var_export($r);
function getIpSegement($num){
if($num<=255){
return '11.0.0.'.$num;
}else if($num>255 && $num<65025){
$four=$num % 255;
$tree = ($num-$four)/255;
return '11.0.'.$tree.'.'.$four;
}
}