repl.it
@x9/

Telnet API

PHP Web Server

Telnet communication API in php.

fork
loading
Files
  • index.php
index.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
<?php
  error_reporting(E_ERROR | E_PARSE);
  class cnc {
    public $ip;
    public $port;
    public $status;
    function __construct($ip,$port,$timeout = 5) {
      error_log("[CNC] Opening new connection to ".$ip.":".$port."...");
      $sock = fsockopen($ip, $port, $errno, $errstr, $timeout) or $this->status = 0;
      if($this->status != 0){
        $this->ip   = $ip;
        $this->port = $port;
        return $sock;
      }else{
        error_log('[CNC] Could not connect.'); 
        die();
      }
    }
    function __destruct() {
      if($this->status != 0){
        error_log("[CNC] Closing connection...");
        fclose($cnc);
      }
    }
    function send_command($cmd){
      error_log("[CNC] Sending command: " + $cmd);
      fwrite($cnc, $cmd."\n") or error_log("[CNC] Command execution failed.");
    }
  }
  $cnc = new cnc("1.2.3.4", "123");
  if($cnc->status != 0){
    echo "<h1>CNC: ".$cnc->ip.":".$cnc->port."</h1>";
  }else{
    echo "connection failed.";
  }
Fetching token
?