How to scan IP range using nmap?

Scripting language : Bash Shell Script

  1. problem statement
    I have to create function in which read IP addresses one by one from one file ( iplist.txt ) and scan these IP using nmap. This scan IP's output is saved in output.txt file and parse output.txt to save only open ports with particular IP in parse.txt file.
    format of parse.txt file:

Code:

ip             port
x.x.x.x        x
  1. My goal:
  2. Find all ports open on a whole range.
  3. Save only open ports with IP address in another file. Don't save filtered or closed ports in this file.

eg. Format of file:
IP_address Open_port

192.168.0.1         21
192.168.0.1         80
....

so I have write the script which scan IP range. I just want script of second option.
I have attached the script. Please help me if possible to implement second option. In second option, my script take open port/tcp and all other details but i want only ip address with open port.

Mumbai University, Mumbai, India and Information Technology

[LEFT]Hi,

Sorry, I don't see an attachment, unless I'm missing something somewhere. You mention attaching the script, but I can't seem to see it, or anything else, attached to your post. If you could have another go at providing your code (as well as any other bits of the homework template that may be missing or incomplete), then it may be possible for us to give you some pointers.
[/LEFT]

Here I have attached file. Please help me

Hi,

Sorry for the delay in replying, I've not been available the last couple of days, but I'll see if I can give you some pointers here. I've taken nmap_scan.txt as the version of your script you intended me to look at, and all line numbers below are based on that file.

The first thing I notice is that you have either mis-spelled or un-defined variables in your script. For example I suspect that you meant to call the variable conunt on line 7 count instead, which you reference in what I surmise must be a debugging loop of some kind in the other attached file, though it does not seem to actually be required for your main script, so this single issue isn't too important.

On a similar note, on line 8 your nmap command is referencing an un-defined variable, line1 . Perhaps you meant to use a variable that contained the currently-read IP address here instead ? You have at least one such variable defined elsewhere in your script that you could use.

Also, on line 10 you reference a file called scan.txt which is not referenced anywhere else in your script. If you meant this to be a line that searches through the output of nmap , then this filename should be the same as the one that nmap wrote its output to.

If you make these changes, you should find that your script runs, and populates parse.txt with the kind of output that you expect.

Hope this helps. If you have any further questions let me know and I'll be happy to assist further if I can.