惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - kongxx

Java & .Net通讯问题 无异间发现的好网站 Message: 因为当前线程不在单线程单元中,故无法实例化 ActiveX 控件 错误处理方法 使用log4net记录日志到MySQL中 C#的MD5实现 Java的MD5实现 microsoft WINDOWS 系统错误代码 [收藏] PicoContainer学习手册 PicoContainer学习手册 Java动态代理实现 [导入]Digester学习笔记 [导入]使用对Ant编程来实现简单文件的打包 [导入]关闭WinXP自带的Zip功能 [导入]使Tomcat可以下载中文文件 [导入].Net中使用com组件后发生System.ArithmeticException异常的解决办法 [导入]使用简单的Web开发架构 [导入].Net配置文件常用配置说明 [导入]使控件拥有透明背景色 [引用] [导入].Net配置log4net
PHP实现的Telnet 【引用】
kongxx · 2005-09-29 · via 博客园 - kongxx

此文来源http://free3.e-168.cn/onlyshep/index.php?action=show&id=36
<?
error_reporting(-1);

class Telnet {
 var $sock = NULL;
 
 function telnet($host,$port) {
  $this->sock = fsockopen($host,$port);
  socket_set_timeout($this->sock,2,0);
 }

 function close() {
  if ($this->sock)  fclose($this->sock);
  $this->sock = NULL;
 }
 
 function write($buffer) {
  $buffer = str_replace(chr(255),chr(255).chr(255),$buffer);
  fwrite($this->sock,$buffer);
 }
 
 function getc() {
  return fgetc($this->sock); 
 }

 function read_till($what) {
  $buf = '';
  while (1) {
   $IAC = chr(255);
   
   $DONT = chr(254);
   $DO = chr(253);
   
   $WONT = chr(252);
   $WILL = chr(251);
   
   $theNULL = chr(0);
 
   $c = $this->getc();
   
   if ($c === false) return $buf;
   if ($c == $theNULL) {
    continue;
   }
 
   if ($c == "1") {
    continue;
   }

   if ($c != $IAC) {
    $buf .= $c;
  
    if ($what == (substr($buf,strlen($buf)-strlen($what)))) {
     return $buf;
    }
    else {
     continue;
    }
   }

   $c = $this->getc();
   
   if ($c == $IAC) {
   $buf .= $c;
   }
   else if (($c == $DO) || ($c == $DONT)) {
    $opt = $this->getc();
    // echo "we wont ".ord($opt)."\n";
    fwrite($this->sock,$IAC.$WONT.$opt);
   }
   elseif (($c == $WILL) || ($c == $WONT)) {
    $opt = $this->getc();
    // echo "we dont ".ord($opt)."\n";
    fwrite($this->sock,$IAC.$DONT.$opt);
   }
   else {
    // echo "where are we? c=".ord($c)."\n";
   }
  }
 }
}

#/$telnet = new telnet("192.168.0.1",23);
#/echo $telnet->read_till("login: ");
#/$tn->write("kongxx\r\n");
#/echo $telnet->read_till("password: ");
#/$tn->write("KONGXX\r\n");
#/echo $telnet->read_till(":> ");
#/$tn->write("ls\r\n");
#/echo $telnet->read_till(":> ");
#/echo $telnet->close();

?>