Created
April 5, 2015 04:18
-
-
Save Moln/893fe4d5001ac8294fbf to your computer and use it in GitHub Desktop.
PHP telnet client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if ( array_key_exists(1, $argv) ){ | |
| $cfgServer = $argv[1]; | |
| } else { | |
| echo "ex: 'php test.php 10.0.0.0 [port]' \n"; | |
| exit; | |
| } | |
| $cfgPort = isset($argv[2]) ? $argv[2] : 23; //port, 22 if SSH | |
| $cfgTimeOut = 10; | |
| $usenet = fsockopen($cfgServer, $cfgPort, $errno, $errstr, $cfgTimeOut); | |
| if (!$usenet) { | |
| echo "Connexion failed\n"; | |
| exit(); | |
| } else { | |
| echo "====> Connected\n"; | |
| stream_set_timeout($usenet, 2); // set the timeout for the fgets | |
| while ($command = fread(STDIN, 1024)) { | |
| fputs($usenet, $command); | |
| $j = 0; | |
| while (!feof($usenet)){ | |
| echo fgets($usenet, 128); | |
| $info = stream_get_meta_data($usenet); | |
| if ($info['timed_out']) { | |
| $j++; | |
| echo "====> Wait timeout $j!\n"; | |
| } | |
| if ($j > 2){ | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| echo "====> End.\r\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment