INTRO
The topic of this article has been picked from our official YouTube channel. instead of reading this article, you can just watch our YouTube video.
Have you ever had fun with Python? well, that’s what this article is all about. you may have made scripts to print star pattern or your name in some different text. but the thing we are going to do is quite different.
we are going to make a python script which will allow us to details of every phone number. we will accomplish this via a python module “phonenumbers
“. it is modules/libraries which make python so great in scripting languages. the power source of python is its libraries. and we will see the perfect example of this in this article.
but let me tell you some requirements before going more further.
Requirements
• Windows System
• Python2 or python3
• pip
ATTACK
I am using my windows 10 machine via ssh. because it is installed on another laptop. so, don’t get freaked out. I will be using Windows PowerShell (Windows command line). If you don’t know much about PowerShell, you don’t need to worry. because I myself have a vague idea of Powershell.
Screenshot:
Now that we have a shell of our windows system, we can run any command on it. Now we will install phonenumbers
lib via pip
command.
pip install phonenumbers
After that, we can use phonenumbers
lib with python ide. type this command to start python ide:
python
Screenshot:
it seems familiar with Linux now. now we will import phonenumbers
lib.
import phonenumbsers
this should give you an error. if it does, you will need to install the lib again for the python that you are running.
To gather info about a phone number, you will need to parse it first.
x = phonenumbers.parse("Country-code+PHONE-NUMBER")
Screenshot:
did you see what happens when we tried to print the variable x? the best thing is you can type the number of any country.
To check if our number is valid or not, we can do something like:
phonenumbers.is_valid_number(x)
Screenshot:
You can check where does the number belong to. to do that you will need to import the geocoder
class from phonenumbers
lib.
from phonenumbers import geocoder geocoder.description_for_number(x, 'en')
Screenshot:
the second argument stands for language. you can type ‘hi’ instead to ‘en’ to see the output in Hindi.
you can also check the carrier name of that number. to do so, you will need to import carrier
class from the phonenumbers
lib.
from phonenumbers import carrier carrier.name_for_number(x, 'en')
Screenshot:
We can make a python script with this module. I have wsl environment installed in my windows so, I can use nano in windows.
Screenshot:
I am not going to teach you python here. you can download this script from my Github page.
CLICK HERE to download script. and remember that I have used sys.argv so now you will have to give a number as an argument for the script.
For example,
python num_track.py <phone-number>
Thanks For visiting.