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.
2 Answers
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
-
Please consider explaining your solution, and go into a little more detail as to why this works. Sep 11, 2018 at 7:29
-
If you use command: curl -sL -w "%{http_code}\n" google.com:443 -o /dev/null you receive code: 200 (OK) - service is working– pcxeljaSep 12, 2018 at 9: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"). Sep 12, 2018 at 9:36
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.