-1

I am doing a nmap bash script, and I am just wondering if there is any possibility to use array list for my port commands. For example:

port=[23,45,75,65]
for i in 21 do

nmap -p x,y 192.168.1.$i

done

e.g. At the x,y place I want to use the number 23,45

bonsaiviking
  • 5,825
  • 1
  • 20
  • 35
rsl
  • 11
  • 1
  • 4

2 Answers2

1

I'm not sure if that's what you want, but you can try this:

ports="23,45,75,65"

for i in 21 do
    nmap -p "$ports" 192.168.1.$i
done

You can also do:

ports="23,45,75,65"
targets="1-25"
nmap -p "$ports" "192.168.1.$targets"
Pierre
  • 6,047
  • 1
  • 30
  • 49
0

Scanning an array of ports is already built in to nmap. See http://nmap.org/book/man-port-specification.html for more details on the syntax, but here's an excerpt that may give you what you need:

For example, the argument -p U:53,111,137,T:21-25,80,139,8080 would scan UDP ports 53, 111,and 137, as well as the listed TCP ports.
childofsoong
  • 1,918
  • 16
  • 23