【问题标题】:Can curl make a connection to any TCP ports, not just HTTP/HTTPS?curl 可以连接到任何 TCP 端口,而不仅仅是 HTTP/HTTPS?
【发布时间】:2013-12-24 10:29:30
【问题描述】:

curl 可以连接到任何 TCP 端口,而不仅仅是 HTTP/HTTPS

我需要检查一个开放的端口,例如:11740

这可能吗?

【问题讨论】:

    标签: php curl


    【解决方案1】:

    是的,有可能,语法是curl [protocol://]<host>[:port],例如:

    curl example.com:1234
    

    如果你使用的是 Bash,你也可以使用pseudo-device /dev files 打开一个 TCP 连接,例如:

    exec 5<>/dev/tcp/127.0.0.1/1234
    echo "send some stuff" >&5
    cat <&5 # Receive some stuff.
    

    另见:More on Using Bash's Built-in /dev/tcp File (TCP/IP)

    【讨论】:

    • 还有curl -v telnet://example.com:1234
    【解决方案2】:

    当然:

    curl http://example.com:11740
    curl https://example.com:11740
    

    端口 80 和 443 只是默认端口号。

    【讨论】:

      【解决方案3】:

      由于您使用的是 PHP,您可能需要使用 CURLOPT_PORT 选项,如下所示:

      curl_setopt($ch, CURLOPT_PORT, 11740);

      请记住,您可能会遇到使用 SELinux 的问题:

      Unable to make php curl request with port number

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-25
        • 1970-01-01
        • 2018-07-01
        • 2012-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多