user2203703
user2203703

Reputation: 2005

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

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

I need to check for an open port, for example: 11740.

Is this possible?

Upvotes: 53

Views: 321442

Answers (3)

kenorb
kenorb

Reputation: 166467

Yes, it's possible, the syntax is curl [protocol://]<host>[:port], for example:

curl example.com:1234

If you're using Bash, you can also use pseudo-device /dev files to open a TCP connection, e.g.:

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

Upvotes: 80

brandonscript
brandonscript

Reputation: 72905

Since you're using PHP, you will probably need to use the CURLOPT_PORT option, like so:

curl_setopt($ch, CURLOPT_PORT, 11740);

Bear in mind, you may face problems with SELinux:

Unable to make php curl request with port number

Upvotes: 11

user2926055
user2926055

Reputation: 1991

Of course:

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

Port 80 and 443 are just default port numbers.

Upvotes: 22

Related Questions