Track Phone Number Location Using Python Step By Step Method

In this tutorial track phone number location using Python step by step method we have shown two different lines of Python code to track phone number or the phone device. You can use it either locate the phone number or the device it’s using. In the first example we have used TKinter while in the second example we have used a different approach by adding few lines of py code.

In this how to track phone number location using Python tutorial we have explains how we can use Python for a phone’s location finding with using a small piece of code step by step.
It’s a basic application created with TKinter that we can use to track phone’s location.You can copy the code part and try it as well.

We need to install the following libraries to do that. Since we already have installed them you’d do that if you have not.

import json 
import pycountry
from tkinter import Tk, Label, Button, Entry
from phone_iso3166.country import phone_country

Use this piece of code written in Python

import json 
import pycountry
from tkinter import Tk, Label, Button, Entry
from phone_iso3166.country import phone_country


class Location_Tracker:
    def __init__(self, App):
        self.window = App
        self.window.title("Phone number Tracker")
        self.window.geometry("500x400")
        self.window.configure(bg="#3f5efb")
        self.window.resizable(False, False)

        # Specification for App menu
        Label(App, text="Enter a phone number",fg="white", font=("Times", 20), bg="#3f5efb").place(x=150,y= 30)
        self.phone_number = Entry(App, width=16, font=("Arial", 15), relief="flat")
        self.track_button = Button(App, text="Track Country", bg="#22c1c3", relief="sunken")
        self.country_label = Label(App,fg="white", font=("Times", 20), bg="#3f5efb")

        #Place widgets on the window
        self.phone_number.place(x=170, y=120)
        self.track_button.place(x=200, y=200)
        self.country_label.place(x=100, y=280)

        #Linking button to locate phone location
        self.track_button.bind("<Button-1>", self.Track_location)
        #255757294146
         def Track_location(self,event):
        phone_number = self.phone_number.get()
        country = "Country is Unknown"
        if phone_number:
            tracked = pycountry.countries.get(alpha_2=phone_country(phone_number))
            print(tracked)
            if tracked:
                    if hasattr(tracked, "official_name"):
                        country = tracked.official_name
                    else:
                        country = tracked.name
        self.country_label.configure(text=country)



PhoneTracker = Tk()
MyApp = Location_Tracker(PhoneTracker)
PhoneTracker.mainloop()

Once it runs the loop, you have added the phone details it will start running this Py script. You will have the country of that number located. So you can further modify this tool by adding some rules to it.

This will locate the country of the phone number. Now here comes the fun part to locate the exact location, its carrier and other details about the phone number. Follow these guidelines to know all the details about that phone number.

There’s another way to locate the phone number you want to track. By using this Python piece of code we have shown below:

import phonenumbers
from text import number
from phonenumbers import geocoder
ch_number = phonenumbers.parse(number, "CH")
print(geocoder.description_for_number(ch_number, "en"))
from phonenumbers import carrier
service_provider = phonenumbers.parse(number, "RO")
print(carrier.name_for_number(service_provider, "en"))

Let’s break it down piece by piece to track the phone number with more details.

#1 Create a new .py Project

Now open pyCharm or any other code processor you use for it. Create a new .py project or click
on the top-left corner of your file.

Choose to Create A New Project.
Use a new project name let’s say Phonetracking and hit ‘Create.’You will see your project location like
this C:\Users\hp\PyCharmProject\Phonetracking

#2 Now right-click the project and ‘Click New.’

#3 Give the Python file a name Add a name to this Python file ending with .py like Tracking.py.

#4  Go to the terminal window at the bottom-left and type this in it to install python phonenumbers libraries.

pip install phonenumbers

Once you run it, it will install python phone numbers library used to parse, format and validate international phone numbers. Once it finishes installing close the terminal.

#5 Import Phonenumbers

Now open Phonetracking.py use this command to import global phonenumbers.

import phonenumbers

#6 Create a new store.py file

Next we need to click the project and add a new file name like store.py to store the number you want to track or the associated device with it.

#7 Add the Phone number to the new .py file

In this new store.py file add the number you want to track with country code. It is important to add the country code starting with a + and to use the exact number you want to track. We have shown example below:

number = "+000000000000000000"

#8 Go to file Tracking.py

Add this code into the file

from text import number
from phonenumbers import geocoder

The first code piece is to add that added phone number to tracking.py file. Here Geocoder is being used a function in phonenumbers. It locates the geographical location correspondence.

#9 Get Phone History

We will parse two parameters to get the phone history so let’s dig more.

In Tracking.py file, write (CH = Country History):

ch_number = phonenumbers.parse(number, "CH")

Next add this code in the same file.

print(geocoder.description_for_number(ch_number, "en"))

“en” is to display phone details in English. Now run the code, by clicking at the top of the screen, hit Enter or Run body you will geolocation of that phone number.

#10 Find out the carrier or the phone network it uses

Add the following code in the Tracking.py file and to see the carrier like Verizon etc that phone number uses.

from phonenumbers import carrier
service_provider = phonenumbers.parse(number, "RO")
print(carrier.name_for_number(service_provider, "en"))

Now run the code again you will see more details added including the carrier or the phone service it uses. This is the best way to track a phone number’s location using Python.