Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

curl

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?

like image 851
user2203703 Avatar asked Dec 06 '13 22:12

user2203703


People also ask

Is curl HTTP or TCP?

Connections - Everything curl. Most of the protocols you use with curl speak TCP. With TCP, a client such as curl must first figure out the IP address(es) of the host you want to communicate with, then connect to it. "Connecting to it" means performing a TCP protocol handshake.

What TCP port does curl use?

Such connections implicitly start out using SSL/TLS and as such servers and clients use TCP port 465 to communicate with each other.

Can TCP and HTTP use same port?

Short answer - NO, you can't have different TCP/HTTP/Websocket servers running on the same port. Longish answer - Both websockets and HTTP work on top of TCP. So you can think of a http server or websocket server as a custom TCP server (with some state mgmt and protocol specific encoding/decoding).

Does curl use 443?

curl simply ignores the port and goes with 443. Of-course, this causes the DNS cache to miss and I end-up using the public DNS IP...


1 Answers

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

like image 177
kenorb Avatar answered Sep 25 '22 06:09

kenorb