0

I know this is a programming forum, but since it's bash scripting - i thought it would be ok to ask here?

Anyway, I am wanting to do a port security assessment of my network at work. We are having a lot of latency issues lately and I suspect one of our users is possibly using a P2P / filesharing program which is against company policies. I am trying to write a bash script to use nmap and make it output the results for each target into its own separate txt file.

I am still fairly new to nmap and bash-scripting (used to mostly be a windows techie... sorry), so i tried something similar to the old DOS batch file programs thinking it would work:

for /l %i in (0,1,255) do nmap -sV 192.168.0.%i > output/192.168.0.%i

Needless to say, it seems to screw up very badly... can anyone help me out here?

Thanks in advance!

Mofi
  • 46,139
  • 17
  • 80
  • 143
Jason
  • 21
  • 1
  • 8
  • Bash and batch are totally different languages with totally different syntaxes. While what you have there would be valid for the Windows command prompt (although you would need to use `%%i` in a batch script), that will not work for bash, unfortunately. – SomethingDark Mar 08 '16 at 03:05
  • This is not what you are asking, but did you know Nmap can scan multiple targets at the same time? You can do what you want in a single command: `nmap -sV -oA outfile 192.168.0.0-255`. Then you can split out the information that you want from the 3 output files it produces: `outfile.nmap`, `outfile.gnmap`, and `outfile.xml` – bonsaiviking Mar 08 '16 at 14:43
  • Thanks for the reply. I checked the link you mentioned and it was exactly what i was looking for - just difficult to google search the right thing when you don't know how to state it. haha. – Jason Mar 09 '16 at 04:26
  • @bonsaiviking yes, i knew that - however it consolidates everything to one file... with several hundred users on our network - i REALLY don't want to go through some 5,000 pages of output to manually split on a per-ip basis. Thanks for the input though! – Jason Mar 09 '16 at 04:29
  • @Jason No need to split at all: the `*.gnmap` format puts all output for one host on a single line, so you can search it with `grep` (`findstr` on Windows). Or split the XML output with an XML parser (PowerShell works great for this, or xmlstarlet) afterwards. You can even use `csplit` to break up the `.nmap` file on "Nmap output for" pattern. But it will go *much* faster scanning all at once vs one at a time. – bonsaiviking Mar 09 '16 at 13:40

0 Answers0