-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbuildwith.py
98 lines (73 loc) · 2.79 KB
/
buildwith.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import requests
import builtwith
from bs4 import BeautifulSoup
import re
R = '\033[31m' # red
G = '\033[32m' # green
C = '\033[36m' # cyan
W = '\033[0m' # white
Y = '\033[33m' # yellow
def analyze_website(url, timeout=10):
try:
response = requests.get(url, timeout=timeout)
html_content = response.text
# Detect programming languages
programming_languages = detect_programming_language(html_content)
# Use builtwith library to get website details
technologies = builtwith.builtwith(url)
# Parse HTML to extract JavaScript libraries
javascript_libraries = extract_javascript_libraries(html_content)
# Get web server information from response headers
web_server = response.headers.get("Server", "Unknown")
return programming_languages, technologies, javascript_libraries, web_server
except requests.Timeout:
return None, None, None, None, "Request timed out"
except Exception as e:
return None, None, None, None, str(e)
# Rest of the code remains unchanged
def detect_programming_language(content):
# Define patterns for various programming languages
patterns = {
"PHP": r"<\?php|\.php",
"Python": r"python",
"Ruby": r"ruby",
"Java": r"\bjava\b",
"JavaScript": r"javascript",
"ASP.NET": r"asp\.net",
}
detected_languages = []
for language, pattern in patterns.items():
if re.search(pattern, content, re.IGNORECASE):
detected_languages.append(language)
return detected_languages
def extract_javascript_libraries(content):
soup = BeautifulSoup(content, "html.parser")
script_tags = soup.find_all("script")
libraries = set()
for script in script_tags:
src = script.get("src")
if src:
match = re.search(r"/(.*?)(?:\.min)?\.js$", src)
if match:
libraries.add(match.group(1))
return list(libraries)
if __name__ == "__main__":
website_url = input("Enter the website URL: ")
programming_languages, technologies, javascript_libraries, web_server = analyze_website(website_url)
if programming_languages:
print("Detected programming languages:", ", ".join(programming_languages))
else:
print("No programming language detected or an error occurred.")
if technologies:
print("\nWebsite technologies:")
for tech, details in technologies.items():
print(f"{tech}: {details}")
else:
print("An error occurred while fetching technologies.")
if javascript_libraries:
print("\nJavaScript libraries:")
for library in javascript_libraries:
print("- " + library)
else:
print("No JavaScript libraries detected.")
print("\nWeb server:", web_server)