This test woudl be for a check explicited mentioned in the eval sheet (check related issue).
This is a possible script in bash, which uses curl which is suggested in the eval sheet. The name of the websites should be changed to the websites we are hosting
#!/bin/bash
# Declare an array of website hostnames
websites=("site1.example.com" "site2.example.com" "site3.example.com")
# Loop through the array of websites
for site in "${websites[@]}"; do
# Use curl to send a request to each site, overriding DNS resolution to 127.0.0.1
response=$(curl -o /dev/null -s -w "%{http_code}" --resolve "${site}:80:127.0.0.1" "http://${site}/")
# Check if the HTTP status code is 200
if [ "$response" -eq 200 ]; then
echo "SUCCESS: ${site} returned status code 200."
else
echo "ERROR: ${site} returned status code ${response}."
fi
done
This is the same in Python.
import requests
List of website hostnames
websites = ["site1.example.com", "site2.example.com", "site3.example.com"]
Loop through the list of websites
for site in websites:
# Construct the URL
url = f"http://{site}/"
# Send the HTTP request, specifying the custom resolution of the domain
try:
response = requests.get(url, headers={'Host': site}, proxies={'http': 'http://127.0.0.1:80'})
# Check if the HTTP status code is 200
if response.status_code == 200:
print(f"SUCCESS: {site} returned status code 200.")
else:
print(f"ERROR: {site} returned status code {response.status_code}.")
except requests.exceptions.RequestException as e:
print(f"ERROR: Could not connect to {site}. Exception: {str(e)}")
@slombard said in WEB-146:
Basically what --resolve do, is sending an http request to example.com:80 as the website would be hosted at the IP address 127.0.0.1. The http request will be send to 127.0.0.1:80 and the Hostname will be 'example.com'.
Basically what they want here is to send different request with curl to different hostnames.
This test woudl be for a check explicited mentioned in the eval sheet (check related issue).
This is a possible script in bash, which uses curl which is suggested in the eval sheet. The name of the websites should be changed to the websites we are hosting
This is the same in Python.
@slombard said in WEB-146: