- HTTP & SOCKS
- Price $1.3/IP
- Locations: DE, RU, US
- 5% OFF coupon: APFkysWLpG
Can curl make a connection to any TCP ports … – Stack Overflow
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?
asked Dec 6 ’13 at 22:22
Yes, it’s possible, the syntax is curl [protocol]
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. 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). answered Feb 11 '16 at 12:21 kenorbkenorb125k68 gold badges605 silver badges641 bronze badges Of course: curl curl Port 80 and 443 are just default port numbers. answered Dec 6 '13 at 22:30 user2926055user29260551, 8029 silver badges10 bronze badges 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 answered Dec 7 '13 at 1:33 brandonscriptbrandonscript59. 4k29 gold badges145 silver badges206 bronze badges Not the answer you're looking for? Browse other questions tagged php curl or ask your own question.
HTTP Rotating & Static Proxies
- 200 thousand IPs
- Locations: US, EU
- Monthly price: from $39
- 1 day moneyback guarantee
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 ordinary command line usage, operating on a URL, these are details which are taken care of under the hood, and which you can mostly ignore. But at times you might find yourself wanting to tweak the specifics…Edit the hosts fileMaybe you want the command curl to connect to your local server instead of the actual can normally and easily do that by editing your hosts file (/etc/hosts on Linux and Unix-like systems) and adding, for example, 127. 0. 1 to redirect the host to your localhost. However this edit requires admin access and it has the downside that it affects all other applications at the same Host: header is the normal way an HTTP client tells the HTTP server which server it speaks to, as typically an HTTP server serves many different names using the same software, by passing in a custom modified Host: header you can have the server respond with the contents of the site even when you did not actually connect to that host example, you run a test instance of your main site on your local machine and you want to have curl ask for the index html:curl -H “Host: localhost/When setting a custom Host: header and using cookies, curl will extract the custom name and use that as host when matching cookies to send Host: header is not enough when communicating with an HTTPS server. With HTTPS there’s a separate extension field in the TLS protocol called SNI (Server Name Indication) that lets the client tell the server the name of the server it wants to talk to. curl will only extract the SNI name to send from the given ovide a custom IP address for a nameDo you know better than the name resolver where curl should go? Then you can give an IP address to curl yourself! If you want to redirect port 80 access for to instead reach your localhost:curl –resolve can even specify multiple –resolve switches to provide multiple redirects of this sort, which can be handy if the URL you work with uses HTTP redirects or if you just want to have your command line work with multiple URLs. –resolve inserts the address into curl’s DNS cache, so it will effectively make curl believe that’s the address it got when it resolved the talking HTTPS, this will send SNI for the name in the URL and curl will verify the server’s response to make sure it serves for the name in the ovide a replacement nameAs a close relative to the –resolve option, the –connect-to option provides a minor variation. It allows you to specify a replacement name and port number for curl to use under the hood when a specific name and port number is used to example, suppose you have a single site called that in turn is actually served by three different individual HTTP servers: load1, load2 and load3, for load balancing purposes. In a typical normal procedure, curl resolves the main site and gets to speak to one of the load balanced servers (as it gets a list back and just picks one of them) and all is well. If you want to send a test request to one specific server out of the load balanced set ( for example) you can instruct curl to do can still use –resolve to accomplish this if you know the specific IP address of load1. But without having to first resolve and fix the IP address separately, you can tell curl:curl –connect-to redirects from a SOURCE NAME + SOURCE PORT to a DESTINATION NAME + DESTINATION PORT. curl will then resolve the name and connect, but in all other ways still assume it is talking to resolve tricks with c-aresAs should be detailed elsewhere in this book, curl may be built with several different name resolving backends. One of those backends is powered by the c-ares library and when curl is built to use c-ares, it gets a few extra superpowers that curl built to use other name resolve backends do not get. Namely, it gains the ability to more specifically instruct what DNS servers to use and how that DNS traffic is using the –dns-servers, you can specify exactly which DNS server curl should use instead of the default one. This lets you run your own experimental server that answers differently, or use a backup one if your regular one is unreliable or –dns-ipv4-addr and –dns-ipv6-addr you ask curl to “bind” its local end of the DNS communication to a specific IP address and with –dns-interface you can instruct curl to use a specific network interface to use for its DNS –dns-* options are advanced and are only meant for people who know what they are doing and understand what these options do. But they offer customizable DNS name resolution will typically make a TCP connection to the host as an initial part of its network transfer. This TCP connection can fail or be slow, if there are shaky network conditions or faulty remote reduce the impact on your scripts or other use, you can set the maximum time in seconds which curl will allow for the connection attempt. With –connect-timeout you tell curl the maximum time to allow for connecting, and if curl has not connected in that time it returns a connection timeout only limits the time curl is allowed to spend up until the moment it connects, so once the TCP connection has been established it can take longer time. See the Timeouts section for more on generic curl you specify a low timeout, you effectively disable curl’s ability to connect to remote servers, slow servers or servers you access over unreliable connection timeout can be specified as a decimal value for sub-second precision. For example, to allow 2781 milliseconds to connect:curl –connect-timeout 2. 781 machines with multiple network interfaces that are connected to multiple networks, there are situations where you can decide which network interface you would prefer the outgoing network traffic to use. Or which originating IP address (out of the multiple ones you have) to use in the curl which network interface, which IP address or even host name that you would like to “bind” your local end of the communication to, with the –interface option:curl –interface eth1 curl –interface 192. 168. 2 curl –interface machine2 TCP connection is created between an IP address and a port number in the local end and an IP address and a port number in the remote end. The remote port number can be specified in the URL and usually helps identify which service you are local port number is usually randomly assigned to your TCP connection by the network stack and you normally do not have to think about it much further. However, in some circumstances you find yourself behind network equipment, firewalls or similar setups that put restrictions on what source port numbers that can be allowed to set up the outgoing situations like this, you can specify which local ports curl should bind the connection to. You can specify a single port number to use, or a range of ports. We recommend using a range because ports are scarce resources and the exact one you want may already be in use. If you ask for a local port number (or range) that curl cannot obtain for you, it will exit with a, on most operating systems you cannot bind to port numbers below 1024 without having a higher privilege level (root) and we generally advise against running curl as root if you can avoid curl to use a local port number between 4000 and 4200 when getting this HTTPS page:curl –local-port 4000-4200 connections can be totally without traffic in either direction when they are not used. A totally idle connection can therefore not be clearly separated from a connection that has gone completely stale because of network or server the same time, lots of network equipment such as firewalls or NATs are keeping track of TCP connections these days, so that they can translate addresses, block “wrong” incoming packets, etc. These devices often count completely idle connections as dead after N minutes, where N varies between device to device but at times is as short as 10 minutes or even way to help avoid a really slow connection (or an idle one) getting treated as dead and wrongly killed, is to make sure TCP keep alive is used. TCP keepalive is a feature in the TCP protocol that makes it send “ping frames” back and forth when it would otherwise be totally idle. It helps idle connections to detect breakage even when no traffic is moving over it, and helps intermediate systems not consider the connection uses TCP keepalive by default for the reasons mentioned here. But there might be times when you want to disable keepalive or you may want to change the interval between the TCP “pings” (curl defaults to 60 seconds). You can switch off keepalive with:curl –no-keepalive change the interval to 5 minutes (300 seconds) with:curl –keepalive-time 300
How to troubleshoot network applications with curl – A2 Hosting
There are many online tools for testing the services offered by a server but those tests only indicate the view from the online tool. Sometimes you need to test connectivity from your local computer. This article describes how to use curl to troubleshoot network of Contents
Using curl to troubleshoot
Troubleshooting web servers
Troubleshooting mail (SMTP) servers
Curl is a command line tool to transfer data from or to a server
Curl is available at the Linux command line, in the Macintosh Terminal and in the Windows Subsystem for Linux. Later versions of Windows 10 include curl in the command prompt. Curl can also be installed from Don’t want to install software? Try our articles on network troubleshooting using telnet or using PowerShell and tnc. Just about every computer will have one of these three programs installed.
To use curl to test basic network connectivity, you need to know several things:
The remote server name or IP address.
The protocol for the service to be tested (HTTP, FTP, SMTP, etc. )
The port number for the network application you want to test.
To open a connection to a remote server, open a terminal window on your computer, and then type curl protocolIP/host:port, where protocol is the communication protocol to be used IP/host represents the IP address or hostname of the server, and port represents the TCP port number. Port is optional when the standard port for a given protocol is used. For example, to connect to on the standard port for, type the following command:
When you try to establish a connection to a remote server, one of two things happens:
The server accepts the connection. If this happens, curl may display some text from the server.
The server rejects the connection. If this happens, you receive a message such as Connection refused or Connect failed.
The following sections demonstrate how to do basic troubleshooting with curl.
Web server testing is probably the most common scenario for network troubleshooting. With curl, you can open a connection to a remote server on port 80 and get a response. Text in red represents commands typed by the user:
$ curl -I
HTTP/1. 1 200 OK
Date: Thu, 14 Feb 2019 20:11:29 GMT
X-Powered-By: PHP/5. 5. 38
curl returns the entire content of the web page by default so in this example the -I option is added to return only the header. The HTTP response confirms that the server is accepting connections and responding to requests.
Use curl to try and connect via SMTP protocol
The following text shows a sample exchange between curl and a remote mail server. Text in red represents commands typed by the user:
$ curl smtp
214 AUTH STARTTLS HELO EHLO MAIL RCPT DATA BDAT NOOP QUIT RSET HELP
The SMTP responses show the server is running and accepting requests.
Some ISPs block port the standard SMTP port (25) to help reduce spam on their you are testing connectivity to an A2 Hosting mail server, you can also use port 2525 or 587.
For example, to try and connect to SMTP on port 2525, add the optional port number at the end of the command. The following text shows a sample exchange between curl and a remote mail server using port 2525. Text in red represents commands typed by the user:
To test an FTP server, use curl to connect via ftp protocol or to port 21.
The following text shows a sample exchange between curl and a remote FTP server. Text in red represents commands typed by the user:
$ curl curl: (67) Access denied: 530
Because a valid user name was not supplied, curl returns Access denied.
More detail is available by using the FTP port (21) without the FTP protocol.
220———- Welcome to Pure-FTPd [privsep] [TLS] ———-
220-You are user number 18 of 50 allowed.
220-Local time is now 12:46. Server port: 21.
220-This is a private system – No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Either response indicat the FTP server is active and running.
SSH uses encrypted connections. However, you can still use curl to verify that the service is running on a server.
The following text shows a sample exchange between curl and a remote SSH server. In this case we use the port number without the protocol. The standard port for ssh is 22 but port 7822 is used by A2 Hosting managed servers. Text in red represents commands typed by the user:
SSH-2. 0-OpenSSH_5. 3
The server returns a response showing the current OpenSSH version indicating the SSH server is active and Informationcurl is a very versatile tool. In addition to the basic connectivity checks shown in this document, it can:
upload and download files
post and retrieve information from web servers
Download and read about curl at the curl website.
Read the curl book online.
Frequently Asked Questions about curl ip port
What port is used by curl?
To test an FTP server, use curl to connect via ftp protocol or to port 21. Because a valid user name was not supplied, curl returns Access denied. More detail is available by using the FTP port (21) without the FTP protocol.Feb 14, 2019
Does curl use port 443?
curl simply ignores the port and goes with 443.Oct 1, 2013
Does curl use TCP or UDP?
The Curl Language provides APIs to use TCP sockets and UDP sockets. Both kinds of sockets use an address/port pair to uniquely identify a socket location. For a client to talk to a server, it must know the address and port that the server is listening on. The Curl socket API can look up an address, given a hostname.