Showing posts with label curl. Show all posts
Showing posts with label curl. Show all posts

Wednesday, 12 March 2025

curl check apache/server version

 curl --HEAD https://mysite.com/

HTTP/1.1 200 OK

Date: Wed, 12 Mar 2025 18:09:35 GMT

Server: Apache/2.4.63 (Unix) OpenSSL/3.0.15

Last-Modified: Wed, 08 Jan 2025 21:56:34 GMT

ETag: "24d-62b38ef635542"

Accept-Ranges: bytes

Content-Length: 589

Content-Type: text/html


Thursday, 13 June 2024

format curl json response

 https://mkyong.com/web/how-to-pretty-print-json-output-in-curl/

 Pretty print JSON with json_pp

This json_pp is typically pre-installed on the Unix/Linux environment. It stands for JSON pretty print. It is less powerful than jq, but it does the job perfectly.

Terminal

curl -s https://api.cloudflare.com/client/v4/ | json_pp

{
   "errors" : [
      {
         "code" : 7000,
         "message" : "No route for that URI"
      }
   ],
   "messages" : [],
   "result" : null,
   "success" : false
}

Tuesday, 9 April 2024

http range request, curl range header,

 http by default allows partial request, so browser/curl can resume download when using range header



to see if server allows partial transmission of data :

https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests

BASH
curl -I http://i.imgur.com/z4d4kWk.jpg
HTTP
HTTP/1.1 200 OKAccept-Ranges: bytes
Content-Length: 146515
If server response Accept-Ranges: byte, then server accepts partial
For GO gin, c.FileAttachement enable or r.static at router level enables range
https://pkg.go.dev/github.com/gin-gonic/gin#Context.File
func (c *Context) FileAttachment(filepath, filename string)

for curl you can request range 

https://everything.curl.dev/http/ranges.html

For browser set up for resumable download visit:
https://stackoverflow.com/questions/38200426/detecting-when-the-browser-has-requested-to-download-a-file

Each time you will get some content  and http response 206
The HTTP 206 Partial Content success status response code indicates that the request has succeeded and the body contains the requested ranges of data, as described in the Range header of the request.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206
curl -r 0-199 http://example.com

Or everything in the file starting from index 200:

curl -r 200- http://example.com

Get 200 bytes from index 0 and 200 bytes from index 1000:

curl -r 0-199,1000-1199 http://example.com/

Saturday, 23 March 2024

CURL send client cert for MTLS also postman

 postman:

https://learning.postman.com/docs/sending-requests/authorization/certificates/

setting is top right beside invite.

when set up Ca and certs, when matching domain APi is called, post man will send request

post man console is on bottom footer beside find and place



CURL:

https://smallstep.com/hello-mtls/doc/client/curl

$ curl --cert client.crt --key client.key --cacert ca.crt https://myserver.internal.net:443

curl ignore CA vallidation for server certs

 -k, --insecure

(SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default. This makes all connections considered "insecure" fail unless -k, --insecure is used.


https://serverfault.com/questions/469824/curl-disable-certificate-verification

Thursday, 7 March 2024

network traceroute , nmap, curl -k

traceroute not displaying:

https://askubuntu.com/questions/1113815/traceroute-is-not-showing-ips-instead-it-showing-stars

traceroute is using UDP probe packets by default - and your firewall settings are blocking them. IIRC Windows tracert uses ICMP - so you could try traceroute -I or traceroute --icmp


Internet Control Message Protocol (ICMP) is used for reporting errors and performing network diagnostics. In the error reporting process, ICMP sends messages from the receiver to the sender when data does not come though as it should.

https://serverfault.com/questions/374620/does-traceroute-use-udp-or-icmp-or-both

the type of packet that is sent differs depending on the implementation. By default Windows tracert uses ICMP and both Mac OS X and Linux traceroute use UDP.


when nmap is blocked use:

https://security.stackexchange.com/questions/124394/nmap-says-host-down-when-host-is-up

 nmap -Pn 192.168.0.171


You can use the -PA and/or -PS commands to check if a host is up or down.

For example:

nmap 192.168.0.171 -PA(port#) -PS(port#) -vv -T5

The -PA and -PS will check if a host is running a stateful or stateless firewall. The -vv is extra verbosity for more output to the terminal. The -T5 is how aggressive the scan will be. Try these out and see what your result is.


curl -k (insecure) disable cert verification

https://serverfault.com/questions/469824/curl-disable-certificate-verification


-k, --insecure

(SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default. This makes all connections considered "insecure" fail unless -k, --insecure is used.

See this online resource for