-
Notifications
You must be signed in to change notification settings - Fork 0
/
favhashgen.py
36 lines (30 loc) · 1.16 KB
/
favhashgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import mmh3
import requests
import argparse
import codecs
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Suppress only the InsecureRequestWarning from urllib3 needed for this example
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def download_favicon(url):
try:
response = requests.get(url, verify=False)
if response.status_code == 200:
return response.content
else:
print(f"Failed to download favicon from {url}. Status code: {response.status_code}")
except Exception as e:
print(f"Error downloading favicon: {e}")
def main():
parser = argparse.ArgumentParser(description="Favicon Hash Calculator")
parser.add_argument("-u", "--url", help="URL of the favicon", required=True)
args = parser.parse_args()
favicon_url = args.url
favicon_data = download_favicon(favicon_url)
if favicon_data:
favicon_base64 = codecs.encode(favicon_data, "base64")
hash_value = mmh3.hash(favicon_base64)
print(f"Favicon Hash: {hash_value}")
else:
print("Favicon data not available. Exiting.")
if __name__ == "__main__":
main()