Port scan a server everyday and save the results

Start

Here is a sample script that uses the nmap command to perform a port scan on a target server, display the open ports report on the screen and schedule it to run every day at 12:00pm:

#!/bin/bash

echo "Enter the target server IP address:"
read target_ip

echo "Scanning ports on $target_ip"

nmap -p- $target_ip > port_scan_result.txt

grep "open" port_scan_result.txt

echo "Port scan complete. Open ports report saved in port_scan_result.txt"

(crontab -l 2>/dev/null; echo "0 12 * * * /path/to/script/port_scan.sh") | crontab -

The script prompts the user to enter the target server IP address, and then uses the nmap command to scan all ports on that IP address. The output of the nmap command is redirected to a file called port_scan_result.txt, and then the grep command is used to filter the output and show only the open ports. The script will display the open ports report on the screen and also save it in the file port_scan_result.txt

The last line schedules the script to run every day at 12:00pm using the cron service. The crontab -l command lists the current cron jobs, and the echo command appends the command to execute the script to the list, and the crontab - command installs the updated cron job list.

Please be aware that port scanning is a security-sensitive task, and it is important to obtain proper authorization before performing a port scan on any server. Additionally, this script is intended for educational and testing purposes only and should not be used for unauthorized or malicious purposes.

Previous Story

S3 Ep117: The crypto crisis that wasn’t (and farewell forever to Win 7) [Audio + Text]

Next Story

Encode a entire directory of files using steganography