Skip to content

Instantly share code, notes, and snippets.

@ArkaprabhaChakraborty
Created July 29, 2023 07:52
Show Gist options
  • Save ArkaprabhaChakraborty/ff7be80bde2d1be077e066ccd36b5699 to your computer and use it in GitHub Desktop.
Save ArkaprabhaChakraborty/ff7be80bde2d1be077e066ccd36b5699 to your computer and use it in GitHub Desktop.
Kali time update script
#!/bin/bash
get_datetime_from_internet() {
local time_server="http://worldtimeapi.org/api/ip"
local response=$(curl -s "$time_server")
if [[ $? -eq 0 && -n "$response" ]]; then
local new_datetime=$(echo "$response" | grep -oE '"datetime":"[^"]+' | cut -d '"' -f 4)
echo "$new_datetime"
fi
}
# Fetch the current date and time from the internet
internet_datetime=$(get_datetime_from_internet)
# Prompt the user to enter the new date and time if internet_datetime is empty
if [[ -z "$internet_datetime" ]]; then
echo "[X] No Internet Connection. Switching to Manual Mode."
read -p "[+] Enter the new date and time (YYYY-MM-DD HH:MM:SS): " new_datetime
else
echo "[+] Date and time set from http://worldtimeapi.org/api/ip"
new_datetime="$internet_datetime"
fi
# Set the new date and time
sudo date -s "$new_datetime"
# Display the updated date and time
echo "[+] Date and time updated to: $(date)"
@ArkaprabhaChakraborty
Copy link
Author

You can move it to /usr/local/bin for ease of use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment