-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.py
43 lines (35 loc) · 1.21 KB
/
checker.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
import socket
import requests
import whois
import nmap
class Checker:
@staticmethod
def is_domain_name_registered(domain_name: str) -> bool:
try:
if socket.gethostbyname(domain_name):
return True
except socket.gaierror:
pass
try:
if domain_name.split(".")[-1:] in whois.validTlds():
if whois.query(domain_name):
return True
except Exception:
pass
top_ports = '21,22,23,25,53,80,110,135,139,443'
nm = nmap.PortScanner()
nm.scan(domain_name, top_ports)
if domain_name in nm.all_hosts():
for proto in nm[domain_name].all_protocols():
for port in nm[domain_name][proto].keys():
if (nm[domain_name][proto][port]["state"] == "open"
or nm[domain_name][proto][port]["state"] == "filtered"):
return True
try:
if requests.get(f"http://{domain_name}"):
return True
if requests.get(f"https://{domain_name}"):
return True
except requests.exceptions.RequestException:
pass
return False