Hello friends, I'm Parvez and this is our fifth video in Python socket
So in the previous video we have learned that how you can create a TCP client socket that
makes a connection to server, to server socket. So this was from the previous example that we have created
In this video I want to show you that how you can convert your IP address
How you can convert the IP address. When you would like to deal with a low level network functions, sometimes the usual string
notation of IP addresses are not useful. By this reason we need to convert these string IP addresses to the packed 32-bit binary formats
Now how you can do this I will show you this. So I have created a new Python file
The first thing I need I'm going to import socket. So I need to import from Banaski import hexalify
Ok now after this let me create a method in here, a conversion I call it
So for IP. Now let me write my IP addresses in here
And you need to add. So this is the string format so 127
This is the local machine IP address and let me write 192.168.0.1
So I want to convert these into 32-bit binary formats. Now first let me write a packed IP address socket.init.atom and you need to add your
IP address in here. And for the unpacked, ip addr socket.init and you need to add your packed IP address
in here. So first let me write and after that I will describe. Now you can print this, so print IP address packed
So this is for the packed and unpacked.format
So this is our IP address and we are going to use the hexalify because we want to convert
our binary data to hexadecimal. And you need to add the packed IP address and we need to add the unpacked IP address. Ok
So now you can call the IP conversion in here. So in this example the two IP addresses, so these are the two IP addresses, have been
converted from a string to a 32-bit packed format using a for n statement
Also the Python, if you see hexalify, Python hexalify function is called from the Benaski module
This helps us to represent the binary data in a hexadecimal format
Now let me just run this. So now let me just run this
We have indentation error. Let me just check this and I will see, I think in here we have, where is the indentation error
Let me just, yeah, this is the error. Ok. Now let me just run this
Now you can see that this is what, I don't have this packed and unpacked
So I don't have the packed. I think I have a problem in this section
Let me just check this. IP address, packed. So this is the problem. Ok
In this section I have a problem
Ok, unpacked. Now let me just run this again
Yeah, now you can see that this is our IP address. This is the packed IP address and this is the unpacked IP address
So like this you can convert your IP address to binary format and I will add the source
code to the video description. If you have any question please let me know and for the further videos please subscribe