| 1 | #!/usr/bin/php |
| 2 | <?php |
| 3 | |
| 4 | $usage = "telnet host [port]\n"; |
| 5 | if($argc > 1) $host = $argv[1]; else die($usage); |
| 6 | $port = 23; if($argc > 2) $port = $argv[2]; |
| 7 | if($argc > 3) die($usage); |
| 8 | |
| 9 | echo("Connecting to $host:$port...\n"); |
| 10 | $sock = pfsockopen($host, $port); |
| 11 | if($sock) echo("Connected!\n\n"); else die("Failed!\n"); |
| 12 | $stdin = fopen('php://stdin', 'r'); |
| 13 | stream_set_blocking($sock, 0); |
| 14 | stream_set_blocking($stdin, 0); |
| 15 | |
| 16 | while(!feof($sock) && !feof($stdin)) { |
| 17 | echo(fgetc($sock)); |
| 18 | fwrite($sock, fgetc($stdin)); |
| 19 | } |