1. 首页
  2. 教程
  3. Linux

利用PHP检测TCP IP端口是否被墙

利用php脚本检测ip是否被墙或者端口是否被墙,代码如下:

<?php
class Health {
  public static $status;
  public function __construct()
  {
  }
  public function check($ip, $port){
    $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    socket_set_nonblock($sock);
    socket_connect($sock,$ip, $port);
    socket_set_block($sock);
    self::$status = socket_select($r = array($sock), $w = array($sock), $f = array($sock), 5);
    return(self::$status); 
  }
  public function checklist($lst){
  }
  public function status(){
    switch(self::$status)
    {
      case 2:
        echo "Closed\n";
        break;
      case 1:
        echo "Openning\n";
        break;
      case 0:
        echo "Timeout\n";
        break;
    }  
  }
}
$ip='IP';
$port=22;
$health = new Health();
$health->check($ip, $port);
$health->status();

需要放在国内机器上即可!

原创文章,作者:admin,如若转载,请注明出处:https://www.huiyingwu.com/3402/

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注