So I’ll just make a multiple line in a single new line over here that is with this line and I’ll just say please enter the type of scan you want to perform so we can just go down because this is a multiline comment. So first of all let’s give one here saying if you want to sync scan and the second one will be UDP scan and the third one here will be comprehensive so this will be three scans and if I put the new line again. So this will be the response from the user or basically to the user. So after that they will just get that number as a print. You have selected option and that will be “resp”. Which is basically the number.nmap scanner using python
So lets check now if (resp=1) so if we just do one. This is not going to work. Because if we see this resp is from input method and we have talked about this in a multiple of times before in the basic Python Lexa that this input method is going to give us this string and this one is basically an integer so we cannot compare this input which is in the form of the string with this one. nmap scanner using python
So we have to pass this as a string.nmap scanner using python So first of all we just compare with the one and if it is the case we have to now do something that is your sync is scanning. So let’s do a syn scanning so first of all let’s nmap scanner using python check for the version of the nmap. So I’ll say nmap version, print this nmap version first. And it will be done with this scanner which you can see here which is the object of this map and will make use of map version method over here.
So this method will be called to check the version of the nmap that is installed on our machine. So next thing is to see that what this scan does. So we have seen this scan was going to give us the dictionary. So let’s see how we can just get the dictionary. So first of all first parameter that is to be seen in this scan is IP address which is entered by the user here. So the next thing was the port range . So I want to check from 1 to 1024 the number of port to be scanned is still here and the next one is argument. So let’s talk about this argument. So first of all see V and the next one is sS.nmap scanner using python
Yes. So what we did here was we just gave the argument to this scan saying that it has to just scan with the verbosity and the SS is to scan for the syn connect acknowledges windows or minimum scans.
If you want to know for further then you can check this documentation
online in this book reference page. So search for V which is obviously our verbosity. So that should be right here. It is saying increase verbosity level and you can also use VB for more greater effect. So this is your argument which is just we just pass right here .And this sS means that we want to just see the TCP syn scanning. So this is the way to put the argument to our scan method. So next thing nmap scanner using python what you need to do is to print that. So basically what we get from here is the dictionary. So I want to get the scanning info from the dictionary. So what this scanning info does is it will just give the Dictionary for the method like syn in services.
So next thing what I want is the IP status so let’s print. If that IP status is up or down. So for that we have to first of all have to type the scanner and we have seen these in a minute before.
Because in that case if I just go to IDLE I’ll so you over here what we just did was in the case of this state. So we just pass here the local host. We saw the state which was up running or not. So we’ll do the same over here. So instead of local host we have to pass IP address that is enter from the user. And now we have to see the state before that. Let me just print some messages over here.
And after i’ll just put the status which will be done with this state method. So we have now the state method which is going to give us the status either up or down and the next thing I want to give here is our protocols which will be TCP protocol. nmap scanner using python
So let’s make use of this method to this a scanner and let’s put again the IP address inside the scanner and let’s check for all protocols.So we will check for the open ports so to do that we have again this scanner and we’ll just pass IP address that is enter from the user.
Now in this case we have to make use of the TCP keys because this is the TCP scanning So we will pass TCP and now we’ll just get the keys which is for the values. So what this result is basically this will give this last statement will give us the dictionary and dictionary will be in the form of the port number. So we’ll get number ports that is open so that can be something like the dictionary which will be in the form of 123 or 45. Any port that is open will be result from this is statement.
So this is our pretty much the first scanning which is our TCP scan. So we have completed our TCP scan over here. Let’s go to the elif part and type something like if the response is greater than maybe 20 then print Invalid something message like this. So first of all I’ll just go to the run run the main so it is showing error.
We have to check if it is one or not. So let’s run this again on the main. It is saying enter the IP address to scan.
So it is going to give us the IP address to scan. So let’s see our IP address from here. IP config (open command prompt).nmap scanner using python
So I’ll just type here my ip address. And it is the message that we just get here now which is saying input which scan we have.
So in this case we have only the one which is obviously the ACK scan which is syn ACK scan. So that means all this put here one. So I’ll just enter one now and it is giving us the selective options
f you see here we are just printing the nmap version so the first thing we get is nmap version and the next we get is this TCP nmap scanner using python so this is in the form of the dictionary which are the result of this scanning for method and it is giving us the method which is obviously sync method which we just did here.nmap scanner using python
This is how you can create you own nmap scanner using python nmap scanner module if you try this on your own system you’ll get a better hold of how this is working and the why we used all those methods like service method to see what are the services , we also saw the protocols method to see the protocols running.
Thanks for Reading.
By : Akash Kumar Singh