I am integrating a payment gateway in the website which is being hosted in a server by a company. This process needs the 2 port to open, I have tested this with one server where I asked them to open the port and they did and my code run fine. But when I asked to open port for another company(hosting) , they say they opened the port but some how my code is not running fine ,there is connection refused message returned to me. So, I want to know if the second company has actually opened the port or not. Is there any way I could see if the port is open or not? The code is in CURL, and also it would be great if server has CURL enabled or not.
Asked
Active
Viewed 1.2k times
3 Answers
3
If you need status code you can use command:
curl -sL -w %{http_code} HOST:PORT -o /dev/null
HTTP Status code: 200 - service is available: More info: https://httpstatuses.com/
For example:
curl -sL -w "%{http_code}\n" https://google.com:443 -o /dev/null

pcxelja
- 39
- 3
-
Please consider explaining your solution, and go into a little more detail as to *why* this works. – dennlinger Sep 11 '18 at 07:29
-
If you use command: curl -sL -w "%{http_code}\n" https://google.com:443 -o /dev/null you receive code: 200 (OK) - service is working – pcxelja Sep 12 '18 at 09:23
-
1First of all, you should update this in your answer (edit it) with proper formatting. Secondly, the explanation should mention *what* the call is doing; the *how* it is getting the result is pretty clear already. E.g., include what the shorthand `-sL -w` is doing, or *why* this is telling you that it is working (something along the lines of "I'm querying the final URL on this port, and it only returns 200 if it is an open port"). – dennlinger Sep 12 '18 at 09:36
0
You can try this:
# curl -v telnet://127.0.0.1:22
* Rebuilt URL to: telnet://127.0.0.1:22/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 22 (#0)
SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
or this
# nc -v 127.0.0.1 22
Connection to 127.0.0.1 22 port [tcp/ssh] succeeded!
SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5

burtsevyg
- 3,851
- 2
- 29
- 44
-4
wget http://hostname:port
This will download some sort of index.html. Alternatively, you can try
curl http://hostname:port
This will open an HTML page.

Melebius
- 6,183
- 4
- 39
- 52

Vineet Tripathi
- 16
- 3