Code Is Bash Script Sh 1 (77.21 KiB) Viewed 22 times
Do: Extend your servicecheck function to receive a list of port/protocol (separated by and check whether any open port is closed: servicecheck() IFS=';' read -r-a arrayports <<< $2 # echo "$(arrayports[1])" nmaplog='nmap $1 for port in "$(arrayports[@]]" do echo $port nmapport- echo $nmaplog | grep $port if [!"$nmapport" ]; then echo 'date': port $port is expected to be open, but its closed >> $logfile fi done } Do: Extend your code in the following way: You receive a file as input that includes in each line the following: IP address, MAC address, ports Example 192.168.10.133, 00:0c:29:bc:e8:3b, 135/tcp:139/tcp;445/tcp Building on the above code, your bash script will do the following For every line in input file, it first pings the IP, then checks to make sure that MAC address is valid, and then checks to make sure that ONLY the mentioned ports are open. This means to check that a port that should be open is not closed, and also any port that is not on the list is closed. It will report any other open port in the log file, in addition to the reports mentioned above. As always, your code must be commented out carefully. Respond: Make sure your code runs correctly. Try it with a bunch finputs. Copy/paste your code in the following textbox. Also, copy/paste your test input file after that. Hint: To read from a file line by line, use the following code: input="/path/to/txt/file" while IFS read -r line. echo "$line" done "$input"
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!