刚刚发现通过PHP, 用telnet方式连接UNIX server 的方法。
RoX~1)etH
.R[eFTYba
这个是一个class 文件. 通过这个class, 可以实现PHP to Telnet 啦。 P1{ub k
�aa+ny
you can download the class here: PHPTelnet Class kb<_ke
o/:u7W?
Usage Examples: f7WQ~j@ML
Q0@&^vThq
Basic usage }]_)`
NOTE: With PHP Telnet versions before 1.1, the following code will not display error messages for certain types of connection failures. If you are using an older version, either upgrade to the current version or use the next code example. N�xUy]fc
1IS( S/
<?php r-{CG_
require_once "PHPTelnet.php"; 2�A;8/Q-
-%5d/@.
$telnet = new PHPTelnet(); VT!@0l`'//
!V%S{)n
// if the first argument to Connect is blank, 1%(.p7I`G
// PHPTelnet will connect to the local host via 127.0.0.1 +0 4+E,Y
$result = $telnet->Connect(' www.somewhere.com','login name','password'); ABt/YZ
wVBs'TKX
if ($result == 0) { Yy!<Tvr~
$telnet->DoCommand('enter command here', $result); uxW 52NNQ
// NOTE: $result may contain newlines 3S8 ;y9'
echo $result; G,7,:S}0~X
$telnet->DoCommand('another command', $result); w/jc"3 >|^
echo $result; S=!e[){
// say Disconnect(0); to break the connection without explicitly logging out m` IPn(;o
$telnet->Disconnect(); >/GOf
} lYc !i6B
?> (F�36.)
xI gh :
Display your own error messages )Vf`N :0U
NOTE: With PHP Telnet versions before 1.1, the show_connect_error option was not supported. If you are using an older version, either upgrade to the current version, or delete the line that sets show_connect_error. 5N$Q>6,8
~ ,<UQ
<?php PH!U[jT
require_once "PHPTelnet.php"; )D+y{zmd"
'RwmN.QH|
$telnet = new PHPTelnet(); 1^D-c$
$telnet->show_connect_error=0; 8@[?7-MEIy
BdD FYV
// if the first argument to Connect is blank, RuZ%`Ss
// PHPTelnet will connect to the local host via 127.0.0.1 91x6'I8G
$result = $telnet->Connect(' www.somewhere.com','login name','password'); y�9{O& yOx
ld+] |,P
switch ($result) { ^ezY<V
case 0: ?a-J h
$telnet->DoCommand('enter command here', $result); ~J}Mzhe~
// NOTE: $result may contain newlines B ^:P R
echo $result; 4�MANDq{
$telnet->DoCommand('another command', $result); PIx 0x
echo $result; q}L�o.
// say Disconnect(0); to break the connection without explicitly logging out -1U3l-R
$telnet->Disconnect(); x ) )"dK
break; DvJaiLMZG
case 1: =cWHwdy5
echo '[PHP Telnet] Connect failed: Unable to open network connection'; )B X3r^
break; 0'hz:%
case 2: C}@|8Qk_
echo '[PHP Telnet] Connect failed: Unknown host'; 6:2(+WV
break; eR<-YxQea
case 3: %$#nAGnqr
echo '[PHP Telnet] Connect failed: Login failed'; S?'.(E
break; aYQncud/
case 4: ]s+"GE=6
echo '[PHP Telnet] Connect failed: Your PHP version does not support PHP Telnet'; ikOK-u&*
break; mnEA`
} Pi.2IbN>~
?>
.R[eFTYba
这个是一个class 文件. 通过这个class, 可以实现PHP to Telnet 啦。 P1{ub k
�aa+ny
you can download the class here: PHPTelnet Class kb<_ke
o/:u7W?
Usage Examples: f7WQ~j@ML
Q0@&^vThq
Basic usage }]_)`
NOTE: With PHP Telnet versions before 1.1, the following code will not display error messages for certain types of connection failures. If you are using an older version, either upgrade to the current version or use the next code example. N�xUy]fc
1IS( S/
<?php r-{CG_
require_once "PHPTelnet.php"; 2�A;8/Q-
-%5d/@.
$telnet = new PHPTelnet(); VT!@0l`'//
!V%S{)n
// if the first argument to Connect is blank, 1%(.p7I`G
// PHPTelnet will connect to the local host via 127.0.0.1 +0 4+E,Y
$result = $telnet->Connect(' www.somewhere.com','login name','password'); ABt/YZ
wVBs'TKX
if ($result == 0) { Yy!<Tvr~
$telnet->DoCommand('enter command here', $result); uxW 52NNQ
// NOTE: $result may contain newlines 3S8 ;y9'
echo $result; G,7,:S}0~X
$telnet->DoCommand('another command', $result); w/jc"3 >|^
echo $result; S=!e[){
// say Disconnect(0); to break the connection without explicitly logging out m` IPn(;o
$telnet->Disconnect(); >/GOf
} lYc !i6B
?> (F�36.)
xI gh :
Display your own error messages )Vf`N :0U
NOTE: With PHP Telnet versions before 1.1, the show_connect_error option was not supported. If you are using an older version, either upgrade to the current version, or delete the line that sets show_connect_error. 5N$Q>6,8
~ ,<UQ
<?php PH!U[jT
require_once "PHPTelnet.php"; )D+y{zmd"
'RwmN.QH|
$telnet = new PHPTelnet(); 1^D-c$
$telnet->show_connect_error=0; 8@[?7-MEIy
BdD FYV
// if the first argument to Connect is blank, RuZ%`Ss
// PHPTelnet will connect to the local host via 127.0.0.1 91x6'I8G
$result = $telnet->Connect(' www.somewhere.com','login name','password'); y�9{O& yOx
ld+] |,P
switch ($result) { ^ezY<V
case 0: ?a-J h
$telnet->DoCommand('enter command here', $result); ~J}Mzhe~
// NOTE: $result may contain newlines B ^:P R
echo $result; 4�MANDq{
$telnet->DoCommand('another command', $result); PIx 0x
echo $result; q}L�o.
// say Disconnect(0); to break the connection without explicitly logging out -1U3l-R
$telnet->Disconnect(); x ) )"dK
break; DvJaiLMZG
case 1: =cWHwdy5
echo '[PHP Telnet] Connect failed: Unable to open network connection'; )B X3r^
break; 0'hz:%
case 2: C}@|8Qk_
echo '[PHP Telnet] Connect failed: Unknown host'; 6:2(+WV
break; eR<-YxQea
case 3: %$#nAGnqr
echo '[PHP Telnet] Connect failed: Login failed'; S?'.(E
break; aYQncud/
case 4: ]s+"GE=6
echo '[PHP Telnet] Connect failed: Your PHP version does not support PHP Telnet'; ikOK-u&*
break; mnEA`
} Pi.2IbN>~
?>