Hi again, welcome to this section of the course. And the fun will begin by planning and learning how to build another network application, which is a simple command line subnet calculator that using an IP address and the subnet mask given by the user will return five parameters, the network address, the broadcast address, the number of valid hosts per subnet, the wildcard mask, and finally the number of mask bits. Finally, our subnet calculator should be able to generate one or more random IP addresses from the subnet in which our initial IP address resides. Sounds pretty cool, right? Let's see it in action right now. So I saved this file on my D drive inside a dedicated folder called network apps.
And this is the Python script right here, subnet calculator, python three.pi. Now let's move on and see how our subnet calculator actually works. And what are we going to achieve At the end, I'm going to execute this Python application, just to give you a taste of what we're about to build. So let me open up the windows command line. And I'm going to type in Python and the path to the file. So the network apps and the name of the file.
Okay, so first, we are asking the user to enter an IP address. So let's try 192 168 dot zero dot two, for instance. Now the user is asked to enter a subnet mask. So let's try 255255255 dot zero. And next the program shows the network address right here. The broadcast address the number of valid hosts per subnet, which is 254.
In this case, the wildcard mask and finally, the number of mask bits. These are the parameters we are looking for when using the subnet calculator most of the times right, so it seems that our application works pretty well. Now the program asks the user if it should generate a random IP address This subnet right here. So if you type in Y for yes, then a random IP address is generated. As you can see right here random IP address is 192 168 dot zero dot eight, and then the program returns to the same question. Maybe the user wants several IP addresses random IP addresses from the subnet to be generated.
If you type in n for no, then the program quits. So let's try yes, one more time to see that indeed, another IP address is generated. And finally, if we hit n for no, then the execution of the program stops. Okay. Now having this application overview in mind, let's dive into planning and analyzing the code. I'll see you in the next lecture.