Skip to content

This Bash script fetches and monitors the public IP address

License

Notifications You must be signed in to change notification settings

Im0nk3yar0und/ippaddr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

IP Address Monitoring Script

This script is designed to monitor the public IP address of a system and log it at regular intervals. It's useful for tracking changes in the system's external IP address, which can be important for network administration and security purposes.


 

Usage

  1. Ensure the script ippaddr.sh is placed in the /root directory.
  2. Adjust the paths and timing in the cron job entries as needed.
  3. The public IP address will be logged to data.log and to ipaddr.log at the specified intervals.

Note

  • Make sure to grant execute permissions to ippaddr.sh (chmod +x ippaddr.sh) before running the cron jobs.
  • Customize the script and cron jobs according to your system's setup and requirements.


 

Dependencies

This script relies on the following dependencies:

  • curl - For fetching the public IP address.
  • mtr - For performing a traceroute.


 

Cron Job Setup

To set up these cron jobs:

  1. Open a terminal or SSH into your server.
  2. Type crontab -e and press Enter to open the crontab file for editing.
  3. Copy and paste the respective cron job entries into the file.
  4. Save and close the file. (In most text editors, you can do this by pressing Ctrl + X, then Y, and finally Enter.)

Ensure that:

  • The paths to your scripts (/root/ippaddr.sh) and log files (/root/ipaddr.log, /root/data.log) are correct.
  • The script ippaddr.sh is executable (chmod +x /root/ippaddr.sh).
@reboot sleep 300 && /root/ippaddr.sh >> /root/data.log 
0 21 * * * sleep 300 && /root/ippaddr.sh >> /root/data.log 
0 0 * * * sleep 300 && /root/ippaddr.sh >> /root/data.log 
@reboot sleep 300 && (echo -n $(date); echo -n " - "; echo $(curl -s https://api.ipify.org/ )) >> /root/ipaddr.log 


 

Explanation

  1. Run the script after 300 seconds : This cron job will execute the script ippaddr.sh after a delay of 300 seconds (5 minutes) when the system reboots, and append the output to a log file.
@reboot sleep 300 && /root/ippaddr.sh >> /root/data.log 
  1. Run the script at 21:00 and at 00:00 every day: This cron job will execute the script ippaddr.sh every day and append the output to a log file.
0 21 * * * sleep 300 && /root/ippaddr.sh >> /root/data.log 
0 0 * * * sleep 300 && /root/ippaddr.sh >> /root/data.log 
  1. Run the script after 300 seconds: Then cron job will run curl to get public ip address and log it to ipaddr.log
@reboot sleep 300 && (echo -n $(date); echo -n " - "; echo $(curl -s https://api.ipify.org/ )) >> /root/ipaddr.log 


 

Internet Service Providers

  • Most home internet service providers assign dynamic IP addresses to their customers, meaning the address changes every two to three days.
  • This is common practice because providers charge extra for a static IP address, which would remain constant for a longer period.
  • This script enables monitoring of the IP address and detecting anomalies, such as static IP addresses that remain unchanged for an extended period.
  • This way, users can track the stability of their internet connection and detect any changes that may indicate issues or unwanted activities on the network.

About

This Bash script fetches and monitors the public IP address

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages