generated from marciopocebon/zoomIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identify_input.py
124 lines (79 loc) · 3.27 KB
/
identify_input.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/python3
##a module to get to know what kind of input is given##
import argparse
import re
import urllib.request
import tldextract
import ipaddress
import what3words
from verify_email import verify_email
parser=argparse.ArgumentParser()
parser.add_argument(
dest='input',help="the input, '_SPACE_' will be handled as spaces ' '"
)
args = parser.parse_args()
input_raw = args.input
input = input_raw.replace('_SPACE_',' ')
w3w_api_key = "62JXOCMQ" #Public API,replace with your own
geocoder = what3words.Geocoder(w3w_api_key)
def is_url():
url = input
parsed = tldextract.extract(url)
domain_without_proto = f'{parsed.domain}.{parsed.suffix}'
domain = f'http://{domain_without_proto}'
try:
http_status = urllib.request.urlopen(domain).getcode()
if http_status == 200:
return True
except:
return False
def is_ip_address():
try:
ip = ipaddress.ip_address(input)
return True
except ValueError:
return False
def is_w3w_address():
w3w_res = geocoder.convert_to_coordinates(input)
return "error" not in w3w_res
def is_first_and_last_name():
regex_name = re.compile(r' ([a-zÄÖÜäöüß]+)( [a-zÄÖÜäöüß]+)*( [a-zÄÖÜäöüß]+)*$',re.IGNORECASE)
return bool(is_name := regex_name.search(input))
def is_username_on_well_known_pages():
username_lookup_url = f"https://knowem.com/checkusernames.php?u={input}"
open_lookup_url = urllib.request.urlopen(username_lookup_url)
is_username_encrypted_output = open_lookup_url.read()
username_resp = is_username_encrypted_output.decode("utf8")
open_lookup_url.close()
return (
"notavailable" in username_resp
and "but we ran into an error" not in username_resp
)
def is_email():
email_pattern = "^[a-zA-Z0-9-_.]+@[a-zA-Z0-9-]+\.[a-z]{2,6}$"
return bool(re.match(email_pattern,input))
#vars are False as standard
input_is_ip_address = False
input_is_url = False
input_is_w3w_address = False
input_is_first_and_last_name = False
input_is_username_on_well_known_pages = False
input_is_email = False
#end of vars
input_is_email = is_email()
input_is_ip_address = is_ip_address() #is it an ip address?
if input_is_ip_address == False: #if not,
if is_w3w_address() == True: #is it a w3w address?
input_is_w3w_address = True
elif is_first_and_last_name() == True:
input_is_first_and_last_name = True
elif input_is_email == False and is_url() == True: #Do not check the subdoamins of the email-address
input_is_url = True #only check for url if input is not something else to make the script faster
elif is_username_on_well_known_pages() == True:
input_is_username_on_well_known_pages = True #only check for url if input is not something else to make the script faster
print("reachable url >",input_is_url)
print("ip address >",input_is_ip_address)
print("w3w address >",input_is_w3w_address)
print("is first and lastname >",input_is_first_and_last_name)
print ("is an email-address >",input_is_email)
print("is username on well-known pages >",input_is_username_on_well_known_pages)