๐Ÿ’ป๋ชจ์˜ํ•ดํ‚น/์นจํ•ด๋Œ€์‘

์›น ์œ„๋ณ€์กฐ ํ™•์ธ ์œ„ํ•œ Python Code ์ž‘์„ฑ

Mark930.k 2023. 4. 28. 12:14

๋‹น์‚ฌ์˜ ์›น ์œ„๋ณ€์กฐ ํ™•์ธ ์œ„ํ•ด Python code ๊ฐ„๋žตํ•˜๊ฒŒ ์ž‘์„ฑ ํ›„ ๊ฒฐ๊ณผ์— ๋Œ€ํ•œ ์œ„๋ณ€์กฐ ์—ฌ๋ถ€ ํ™•์ธ

import urllib.request
from urllib.error import URLError
from urllib.parse import urlparse

def check_for_web_forgery(url):
    try:
        # Make a request to the URL
        response = urllib.request.urlopen(url)

        # Check for unexpected redirects
        final_url = response.geturl()
        if final_url != url:
            return f"Warning: redirected to {final_url}"

        # Check for mismatched domain names
        parsed_url = urlparse(url)
        parsed_final_url = urlparse(final_url)
        if parsed_url.netloc != parsed_final_url.netloc:
            return f"Warning: domain name mismatch ({parsed_url.netloc} != {parsed_final_url.netloc})"

        # No signs of forgery found
        return "No forgery detected"

    except URLError as e:
        # There was an error making the request
        return f"Error: {e.reason}"



url = "https://idblife.com"
result = check_for_web_forgery(url)
print(result)

๊ฒฐ๊ณผ ๋‚ด์šฉ