-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.php
executable file
·91 lines (74 loc) · 2.42 KB
/
client.php
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
90
91
#!/usr/bin/env php
<?php
set_time_limit(0);
ini_set("default_socket_timeout", 6000);
function getDATA() {
#return 'data='.randString( rand(200,300) );
return file_get_contents('data.sample.packet');
}
$conf = json_decode(file_get_contents('conf.json'),true);
list($host, $port) = isset($argv[2]) ? explode(':',$argv[2]) : array($conf['putbind'],$conf['putport']);
$BOARDS = array('0001','0002','0003','9999');
while(1):
unset($sock);
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$timeout = array('sec'=>2,'usec'=>0);
socket_set_option($sock,SOL_SOCKET,SO_RCVTIMEO, $timeout);
$res = socket_connect($sock, $host, (int)$port);
if($res===false) {
echo "Unable to connect to $host:$port\n";
sleep(1);
continue;
}
$BOARDID = $BOARDS[array_rand($BOARDS)];
$head = "POST / HTTP/1.1"."\r\n".
"Host: ".$host."\r\n".
"Content-Type: application/x-www-form-urlencoded"."\r\n".
"User-Agent: CLIENTPHP_".$BOARDID."\r\n".
"Connection: keep-alive"."\r\n".
"Authorization: Basic ".base64_encode($conf['putuser'].':'.$conf['putpass'])."\r\n".
"Content-Length: 10000000"."\r\n".
//"Content-Length: 500"."\r\n".
//'Content-Length: '.strlen(getDATA())."\r\n".
"\r\n"."\r\n";
// !!! questo content-length rappresenta la lunghezza totale dei pacchetti accettati
$headShort = '';
// 'POST / HTTP/1.1'."\r\n".
// 'Connection: keep-alive'."\r\n".
// 'Content-Length: '.strlen(getDATA())."\r\n".
// "\r\n"."\r\n";
$interval = 100000;
$first = true;
$maxpackets = 5000;
while($maxpackets--)
{
echo "\n\n[CLIENT ".date('H:i:s ').', BOARD: '.$BOARDID.", Interval: $interval]:\n";
echo $out = ($first ? $head : $headShort).getDATA();
if($first) {
$first = false;
// echo "\n[SERVER]:\n";
// while(!feof($sock)) //stampa tutta la risposta del server
// echo fread($sock, 200);
//inutile xke il server manda output solo in caso il client non sia auteticato
}
if(socket_write($sock, $out)===false)//$out.chr(0)
{
echo "\ndisconnected!";
break;
}
// if($maxpackets<496) //aumenta intervallo dopo qualche pacchetto per testare timeout
// $interval = 10;
usleep($interval);
}
socket_close($sock);
sleep(2);
endwhile;
function randString($length = 10) {
$characters = '0123456789ABCDEF,*.)';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
?>