track-phone-number-using-python

Track Phone Number Using Python

Introduction:

Python is a compelling language and also very rich in libraries. phone numbers are one of the modules that provide numerous features like providing basic information about a phone number, validation of a phone number, etc. Here, we will learn how to use the phone numbers module just by writing simple Python programs. This is a Python port of Google’s libphonenumber library.

Project Prerequisites: 

· You have to install the package called phone numbers for this project.

· To know more about the phonenumbers package can read this documentation – https://pypi.org/project/phonenumbers/

Command for installing phonenumbers through cmd – pip install phonenumbers

Getting Started:

NOTE: I will be using PyCharm Community Edition IDE.So, the steps I mention are specific to that IDE only.

You can also write the program in the IDE of your choice; I have mentioned the requirements in the end notes of this article. 

First of all, we need to create a project folder named – “LocationFinder” and create a python file named main.py

Installing the required package: 

· Click on the file button and then Settings, or you can directly press Ctrl+Alt+S

to open the settings

· There, you will find the Project: LocationFinder option. Click on that and then on the Python Interpreter.

· Now, to install the phone number package, click on the ‘+’ symbol above the Package and search for phonenumbers and then click Install Package.

See also  50+ Best python projects with source code [2023]

Code Implementation:

First, we import the phonenumbers package.

From that, we will be importing the timezone module – this will be used to print the timezone the number is in.

We will also import geocoder and carrier modules to get the geological location and the service provider name, respectively.

import phonenumbers
from phonenumbers import timezone
from phonenumbers import geocoder
from phonenumbers import carrier

import phonenumbers
from phonenumbers import timezone
from phonenumbers import geocoder
from phonenumbers import carrier

After that, we will take input the phone number that is to be tracked. The phone number has to be entered along with the country code.
number = input(“Enter the phone number with country code : “)

number = input("Enter the phone number with country code : ")

Now that we have taken the input of the phone number in the form of a string, we need to convert it into phone number format, and this is done using the parse( ) method of the phonenumber module.

#Parsing String to the Phone number

phoneNumber = phonenumbers.parse(number)
# Parsing String to the Phone number
phoneNumber = phonenumbers.parse(number) 

After that, we will be using the phoneNumber to print the timezone, geo-location, and service provider name of the entered phone number.

First, we will use the timezone module to print the timezone of the given phone number.

We use the time_zones_for_number( ) method to get the time zone.

# printing the timezone using the timezone module

timeZone = timezone.time_zones_for_number(phoneNumber)

print(“timezone : “+str(timeZone))

# printing the geolocation of the given number using the geocoder module
geolocation = geocoder.description_for_number(phoneNumber,"en")
print("location : "+geolocation)

Last, we print the carrier/service provider name with the help of the name_for_number( ) method from the carrier module.

See also  Build a GUI with Tkinter and automate MS Word with Python

# printing the service provider name using the carrier module

service = carrier.name_for_number(phoneNumber,”en”)

print(“service provider : “+service)

# printing the service provider name using the carrier module
service = carrier.name_for_number(phoneNumber,"en")
print("service provider : "+service)

Source Code:

Here is the complete source code:

# track location and time zone using the phone number
import phonenumbers
from phonenumbers import timezone
from phonenumbers import geocoder
from phonenumbers import carrier

number = input("Enter the phone number with country code : ")

# Parsing String to the Phone number
phoneNumber = phonenumbers.parse(number)

# printing the timezone using the timezone module
timeZone = timezone.time_zones_for_number(phoneNumber)
print("timezone : "+str(timeZone))

# printing the geolocation of the given number using the geocoder module
geolocation = geocoder.description_for_number(phoneNumber,"en")
print("location : "+geolocation)

# printing the service provider name using the carrier module
service = carrier.name_for_number(phoneNumber,"en")
print("service provider : "+service)

Output:

Woo-hoo! That’s all for the code.

Now let’s run and see the output. The output should look something like this:

If your output looks like the above image then congratulations. You have done it.

Important Note:

NOTE: This program can be executed in any IDE of your choice. You only need to install the phonenumbers package using the cmd

Leave a Comment

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

we provide projects, courses, and other stuff for free. in order for running we use Google ads to make revenue. please disable adblocker to support us.