You are not logged in.

#1 2024-12-01 12:33:07

xerxes_
Member
Registered: 2018-04-29
Posts: 815

[SOLVED] IP address check + date & time: save all to file

Because my ip address changes very often and I wanted to know how often it changes I wanted to do one liner (to do from it an alias) to get ip address, time at which it was checked and write it to file, but only date and time is saved to file, not ip address.

How to write it all (from do to sleep, but not sleep)?

I was trying like this:

while true; do curl ipinfo.io/ip; printf ' '; date +%Y%m%d%H%M%S >> /tmp/ip; sleep 5m; done
while true; do curl ipinfo.io/ip; printf ' '; date +%Y%m%d%H%M%S &>> /tmp/ip; sleep 5m; done

The format should be:
ip adr (space) date & time - first check
ip adr (space) date & time - second check
...
ip adr (space) date & time - n-th check

EDIT:

I done it in that way:

while true; do echo "$(curl -s ipinfo.io/ip) $(date +%Y-%m-%d_%H:%M:%S)" >> /tmp/ip; sleep 5m; done &

Last edited by xerxes_ (2024-12-01 16:30:42)

Offline

#2 2024-12-01 21:50:05

xerxes_
Member
Registered: 2018-04-29
Posts: 815

Re: [SOLVED] IP address check + date & time: save all to file

Interesting: while using this script in background my IP address didn't change for few hours, but when I close it my IP address changed 2 times in about hour.
What can be said about this behavior? What can be said about my internet provider? It looks suspicious...

Offline

#3 2024-12-01 22:45:05

cryptearth
Member
Registered: 2024-02-03
Posts: 1,090

Re: [SOLVED] IP address check + date & time: save all to file

what's the actual type of your connection? dsl? coax? fiber? mobile?
also: does the ip you get match what your modem shows? could be carrier-grade nat with randomly changing exit-nodes (kinda like TORs auto re-route) for load balancing
the more interesting quesion is: why seem the ip stable with the script constantly query it from an external source but changes when this isn't the case any longer?
do you have some public endpoint you can establish a heartbeat tunnel to like some public ssh endpoint? using such and keep pinging the remote ever couple seconds should break the moment your ISP switches the endpoint - or maybe have some logic in place to prevent this when a long time session is detected (like a download of some big file taking some time - which could also be an option: https://ash-speed.hetzner.com/ )

Offline

#4 2024-12-02 07:26:28

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,129
Website

Re: [SOLVED] IP address check + date & time: save all to file

You need to redirect curl ipinfo.io/ip; and the spacing to the file, too:

while true; do curl ipinfo.io/ip >> /tmp/ip; printf ' ' >> /tmp/ip; date +%Y%m%d%H%M%S >> /tmp/ip; sleep 5m; done

Inofficial first vice president of the Rust Evangelism Strike Force

Offline

#5 2024-12-02 11:55:26

xerxes_
Member
Registered: 2018-04-29
Posts: 815

Re: [SOLVED] IP address check + date & time: save all to file

cryptearth wrote:

what's the actual type of your connection? dsl? coax? fiber? mobile?

This is vdsl2 modem/router through ethernet cable. It has set ipv6 address by internet provider, ipv4 is for this modem less important. And through this site I can't check ipv6 address.

cryptearth wrote:

the more interesting quesion is: why seem the ip stable with the script constantly query it from an external source but changes when this isn't the case any longer?

Yes, that's what I asking.

cryptearth wrote:

do you have some public endpoint you can establish a heartbeat tunnel to like some public ssh endpoint?

No.

@schard
Thanks, that also works, but I would add '-s' option to curl.

Offline

Board footer

Powered by FluxBB