I am trying to create a simple bash script that can run the "specific" port scan on mulitple IPs and Ports using nmap -p. The issue I am having is that when it reads the port# followed by the IP from the .txt file, the text file has the necessary space between port and IP, but it causes the script to fail. The code I have is below. I was trying to make this simple the only other thing I can think of is creating an array, but even then I am thinking that format for the nmap -p port scan is going to have the same issue. Any suggestions?
for i in $(cat 'filepathway')
do
nmap -p $i
done
its executing this: nmap -p 'port#'
instead of this: nmap -p 'port#' 'IP#'
The .txt looks like this:(these values are random)
23001 172.55.545.254
23002 172.55.545.254
...
I am using command: xargs -L 1 nmap -p <file.prn
– Tricepticon Jan 17 '22 at 20:18which leads me to believe that the return line and new line are being registered into the command and causing it to fail.
Any thoughts? Am I missing something?
– Tricepticon Jan 17 '22 at 20:18dos2unix
to convert it, or tell Excel to do the right thing from the start), don't use-L 1
. – Kusalananda Jan 17 '22 at 21:18xargs
if you want to use specific ports (I hope I made this clear in the answer). In my previous comment, I said "don't use-L 1
", You should use-L 1
i you only have IP-addresses in the file, as I mentioned in my answer. I misread your other comments, that's why I was slightly confused. If you have port numbers and IP-addresses in a tab-delimited file, then use my loop variation at the end of the answer (you can't usexargs
in this case). – Kusalananda Jan 17 '22 at 22:09