Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Herausforderung: Überprüfen Sie das Webprotokoll der Website | Web-Cybersicherheit
Grundlagen der Cybersicherheit

book
Herausforderung: Überprüfen Sie das Webprotokoll der Website

Aufgabe

Swipe to start coding

Lass uns eine einfache Funktion erstellen, die eine grundlegende Anfrage an eine Website sendet und überprüft, ob HTTPS verwendet wird.
Deine Aufgabe ist:

  1. Sende eine Anfrage und überprüfe, ob der Antwortstatuscode 200 entspricht. Dies ist notwendig, um die Erreichbarkeit der gewählten URL zu prüfen.
  2. Überprüfe, ob die Antwort-URL mit dem Teilstring https beginnt. Dies weist darauf hin, dass unsere Quelle das HTTPS-Webprotokoll verwendet.
  3. Rufe die Funktion check_https_protocol() mit der entsprechenden URL als Argument auf, um sie zu überprüfen.

Hinweis

Obwohl unsere URL ('http://codefinity.com') zunächst die Verwendung des HTTP-Protokolls anzeigt, könnte der Server sie gemäß seinen serverseitigen Konfigurationen auf HTTPS umleiten. Unser Ziel ist es, die Unterstützung von HTTPS durch den Server zu ermitteln, indem wir dessen Konfigurationen untersuchen. Bei Erfolg wird unsere Anfrage umgeleitet und die Antwort-URL beginnt mit 'https'.

Lösung

import requests # Import the requests library for making HTTP requests

def check_https_protocol(url):
try:
# Send an HTTP GET request to the specified URL
response = requests.get(url)
# Check if the response status code is 200 (OK)
if response.status_code == 200:
# Check if the URL starts with 'https'
if response.url.startswith('https'):
return f'The website {url} uses HTTPS. It is secure.'
else:
return f'The website {url} does not use HTTPS. It is not secure.'
else:
# If the response status code is not 200, return an error message
return f'Error: Unable to connect to {url}.'
except requests.exceptions.RequestException as e:
# Handle any exceptions that may occur during the request (e.g., network issues)
return f'Error: {e}'

# Example usage:
url_to_check = 'http://codefinity.com'
result = check_https_protocol(url_to_check)
print(result)

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 3
import requests # Import the `requests` library for making HTTP requests

def check_https_protocol(url):
try:
# Send an HTTP GET request to the specified URL
response = requests.get(url)
# Check if the response status code is 200 (OK)
if response.status_code == ___:
# Check if the URL starts with 'https'
if response.url.startswith('___'):
return f'The website {url} uses HTTPS. It is secure.'
else:
return f'The website {url} does not use HTTPS. It is not secure.'
else:
# If the response status code is not 200, return an error message
return f'Error: Unable to connect to {url}.'
except requests.exceptions.RequestException as e:
# Handle any exceptions that may occur during the request (e.g., network issues)
return f'Error: {e}'

# Example usage:
url_to_check = 'http://codefinity.com'
result = ___(url_to_check)
print(result)

Fragen Sie AI

expand
ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

some-alt