从php进行端口检查 [英] Port checking from php

查看:106
本文介绍了从php进行端口检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从phplist安装连接到gmail pop服务器,但失败,但是我不确定我的网络主机是否打开了995端口.他们说他们已经打开了,但是我对此表示怀疑.有没有一种方法可以从php脚本中检查它?他们在Windows服务器上运行php 5.2.0,尽管我不确定那是什么操作系统. phpinfo()说"Windows NT DEDI514 5.2 build 3790"

I'm trying to connect to gmail pop server from a phplist installation and it fails, but i'm not sure whether my webhost opened port 995 or not. They say they have opened it, but i'm in doubt. Is there a way i can check it from a php script? They are running php 5.2.0 on a windows server, though i'm not sure what OS is that. phpinfo() says "Windows NT DEDI514 5.2 build 3790"

推荐答案

您可以将代码放入php脚本中,以打开到特定主机名(或IP地址)和端口的连接. 如果您知道预期的响应,则应该能够确定是否获得连接.如果出现拒绝连接"之类的消息,则说明您被阻止,或者目标主机不接受该端口上的连接.

You can put code in a php script to open a connection to a specific hostname (or IP address) and port. If you know the expected response, you should be able to tell if you are getting a connection. If you get something like "Connection refused", then either you are being blocked, or the destination host is not accepting connections on that port.

此示例使用IP地址192.0.2.0和端口995.将它们替换为要测试的任何内容.

This example uses IP address 192.0.2.0 and port 995. Replace these with whatever you want to test.

<?php
    echo "\nOpening connection\n\n";

    $fp = fsockopen("192.0.2.0", 995, $errno, $errstr);
    if (!$fp) {
        echo "ERROR: $errno - $errstr\n";
    } else {
        echo fread($fp, 1024);
        fclose($fp);
    }
?>

您还可以使用以下方式将数据发送到服务器:

You can also send data to the server using

fwrite($fp, "blah blah blah\r\n");

有关此处的fsockopen的更多信息.

There is more information about fsockopen here.

这篇关于从php进行端口检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆