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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:11:43  来源:igfitidea点击:

Can curl make a connection to any TCP ports, not just HTTP/HTTPS?

phpcurl

提问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 的问题:

Unable to make php curl request with port number

无法使用端口号发出 php curl 请求

回答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).

另请参阅:有关使用 Bash 的内置 /dev/tcp 文件 (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 只是默认端口号。