Menu
phone numbers

Tracking phone numbers using python!

In this article, I will be sharing with you how to track phone numbers of any sim of any country using python just by a typing a few lines of magic."

The task will be done by importing a module called phonenumbers. It is not a pre installed module , so we have to install it using PIP. This is a Python port of Google's libphonenumber library It supports Python 2.5-2.7 and Python 3.x.

python module for phone numbers

Whats the code?

Firstly install and import the prerequisites.

Follow the given steps:-

  • Install the module 'phonenumbers' by using 'pip install phonenumbers'
  • Import the following modules
  • 
        import phonenumbers
        from phonenumbers import geocoder,carrier
    

  • Then we have to make a list containing all the numbers. Ensure the the numbers are preeceded by their respective country codes
  • 
        numbers= ["+917070190843","+917360022111","+919898666987"]
    

  • Then we have to perform all the list functions
  • 
        length = len(numbers)
        i= 1
        j=0
    

  • The last step is to start a while loop and iter all the elements of the list.
  • 
        while i<= length:
        for item in numbers:
            num= f"phoneNumber{i}"
            num = phonenumbers.parse(item) 
            
            Carrier = carrier.name_for_number(num, 'en') 
            Region = geocoder.description_for_number(num,'en') 
            print("Number: ",numbers[j])
            print("Carrier: ",Carrier) 
            print("Region: ",Region) 
            print()
            print()
            i+=1
            j+=1
    

  • The num function is the parsed version of the string we wrote in the list. The phone numbers have to be parsed in order to be recognized by the phone numbers module.
  • The Carrier function tells about the company whose sim is used and the Region function tells about the country in which the sim is located.

  • Output

    
        Number:  +917070190843
        Carrier:  Airtel      
        Region:  India        
         
    
        Number:  +917360022111
        Carrier:  Vodafone    
        Region:  India        
    
    
        Number:  +918986665159
        Carrier:  BSNL MOBILE 
        Region:  India        
    
    
  • Here is the compiled code:
  • 
        import phonenumbers
        from phonenumbers import geocoder,carrier
        numbers= ["+917070190843","+917360022111","+919898666987"]
        length = len(numbers)
        i= 1
        j=0
        while i<= length:
        for item in numbers:
            num= f"phoneNumber{i}"
            num = phonenumbers.parse(item) 
            
            Carrier = carrier.name_for_number(num, 'en') 
            Region = geocoder.description_for_number(num,'en') 
            print("Number: ",numbers[j])
            print("Carrier: ",Carrier) 
            print("Region: ",Region) 
            print()
            print()
            i+=1
            j+=1
    
  • And thats it, you have learnt how to find out the location of any phone number and also its carrier information.
  • Happy Coding!