Curl
Return status code only
curl -s -o /dev/null -w "%{http_code}" google.com
curl -s -o /dev/null -i -w "%{http_code}" google.com
curl -s -o /dev/null -I -w "%{http_code}" google.com
curl -s -o /dev/null -I -w "%{http_code}\n" google.com
ref: [1]
Return fail status code
curl --fail http://some-url.com echo $?
-f, --fail (HTTP) Fail silently (no output at all) on server errors
Connect to server by ip and pass hostname
Option #1:
- Add to C:\windows\system32\drivers\etc\hosts
Option #2: (will convert connection of example.com to altexample.com) [2]
curl --connect-to example.com:80:altexample.com:80 http://example.com # shorthand: curl --connect-to ::altexample.com http://example.com curl --connect-to ::altexample.com:8080 http://example.com
Option #3:
curl --resolve <host:port:address> <URL> host: The hostname you want to use in the request. port: The port number for the connection. address: The IP address you want to connect to. URL: The URL you want to request, using the specified hostname.
curl --resolve example.com:443:192.168.1.100 https://example.com
- "This command will send a request to the IP address 192.168.1.100, but it will include example.com in the Host header, which is crucial for virtual hosting and TLS/SSL certificate validation."
Option #4: (this does not seem to work??)
curl [IP] -k -H 'Host: example.com'