Last active
March 18, 2024 13:55
-
-
Save Lathanao/82d18e0a97559a79dd987e3f0ae6b9b4 to your computer and use it in GitHub Desktop.
Ip tracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -xe | |
# Ip tracker (MIT License) | |
# By Lathanao (last update: 18/03/2024) | |
# | |
# Script work well when that has been set: | |
# $ echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/no-more-password" | |
# $ sudo ln -s /dir/of/Scripts/* /etc/cron.daily/ | |
LOG_DIR=/var/log/usercron | |
LOG_FILE=/var/log/usercron/ip-tracker.log | |
if [[ ! -d "$LOG_DIR" ]];then | |
sudo mkdir -p $LOG_DIR | |
sudo chmod -R 0700 $LOG_DIR | |
sudo chown -R $USER:$USER $LOG_DIR | |
fi | |
if [[ ! -f "$LOG_FILE" ]];then | |
sudo touch $LOG_FILE | |
sudo chmod 0700 $LOG_FILE | |
sudo chown $USER:$USER $LOG_FILE | |
fi | |
REAL_IP=`curl ifconfig.me/ip` | |
IP=`ip -6 addr show wlo1 scope global | grep -oP '(?<=inet6\s)[\da-f:]+'` | |
GET_ROUTE=`ip route get 1.2.3.4` | |
DATE=$(date +"%Y-%m-%d %T") | |
echo $DATE $(whoami) $REAL_IP $IP $GET_ROUTE >> $LOG_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment