php curl 可以连接到任何 TCP 端口,而不仅仅是 HTTP/HTTPS?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20434620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can curl make a connection to any TCP ports, not just HTTP/HTTPS?
提问by user2203703
Can curlmake a connection to any TCP ports not just HTTP/HTTPS
可以curl连接到任何 TCP 端口,而不仅仅是 HTTP/HTTPS
I need to check for an open port, for example: 11740.
我需要检查一个开放的端口,例如:11740.
Is this possible?
这可能吗?
采纳答案by brandonscript
Since you're using PHP, you will probably need to use the CURLOPT_PORToption, like so:
由于您使用的是 PHP,您可能需要使用该CURLOPT_PORT选项,如下所示:
curl_setopt($ch, CURLOPT_PORT, 11740);
curl_setopt($ch, CURLOPT_PORT, 11740);
Bear in mind, you may face problems with SELinux:
请记住,您可能会遇到 SELinux 的问题:
回答by kenorb
Yes, it's possible, the syntax is curl [protocol://]<host>[:port], for example:
是的,有可能,语法是curl [protocol://]<host>[:port],例如:
curl example.com:1234
If you're using Bash, you can also use pseudo-device /devfilesto open a TCP connection, e.g.:
如果您使用 Bash,您还可以使用伪设备/dev文件来打开 TCP 连接,例如:
exec 5<>/dev/tcp/127.0.0.1/1234
echo "send some stuff" >&5
cat <&5 # Receive some stuff.
See also: More on Using Bash's Built-in /dev/tcp File (TCP/IP).
回答by user2926055
Of course:
当然:
curl http://example.com:11740
curl https://example.com:11740
Port 80 and 443 are just default port numbers.
端口 80 和 443 只是默认端口号。

