-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace_phone.py
33 lines (26 loc) · 999 Bytes
/
trace_phone.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
"""
Phone number country and location tracing
in Python with phonenumbers library
"""
# pip install phonenumbers
import phonenumbers
from phonenumbers import geocoder, carrier
def trace_phone_number(phone_number):
try:
parsed_number = phonenumbers.parse(phone_number, None)
country = geocoder.country_name_for_number(parsed_number, 'en')
location = geocoder.description_for_number(parsed_number, 'en')
subscriber_name = carrier.safe_display_name(parsed_number, 'en')
return country, location, subscriber_name
except phonenumbers.phonenumberutil.NumberParseException:
return None, None
# testing the code
phone_number = "+14155534673"
country, location, subscriber_name = trace_phone_number(phone_number)
if country and location:
print('Country:', country)
print('Location:', location)
print('Service provider:', subscriber_name)
else:
print("Unable to trace the phone number.")
print(dir(carrier))