From 7aa21bd2fd75f8949cd6db69db8ba7a801df37b5 Mon Sep 17 00:00:00 2001 From: lookshe Date: Sun, 21 Sep 2014 00:37:43 +0200 Subject: perl script for logging external ip address and analysing changes from its logfile --- externalIp.pl | 6 ++++++ ipchanges.pl | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 externalIp.pl create mode 100644 ipchanges.pl diff --git a/externalIp.pl b/externalIp.pl new file mode 100644 index 0000000..2220d9d --- /dev/null +++ b/externalIp.pl @@ -0,0 +1,6 @@ +#!/usr/bin/perl + +($ip=`wget -q -O - http://checkip.dyndns.org`)=~s/\n$//; +$ip=~s/.*[^\d](\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[^\d].*/$1/; +($date=`date`)=~s/\n$//; +print "$date\n$ip\n"; diff --git a/ipchanges.pl b/ipchanges.pl new file mode 100644 index 0000000..5b3211a --- /dev/null +++ b/ipchanges.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +my $file = "/home/lookshe/myips.txt"; + +open(FILE, $file) || die("unable to open $file!"); +my @lines = ; +close(FILE); + +for ($i = 1; $i <= $#lines-2; $i+=2) +{ + my $ip = $lines[$i]; + chomp($ip); + my $nextip = $lines[$i+2]; + chomp($nextip); + if ($ip !~ m/^$nextip$/) + { + my $time = $lines[$i+1]; + chomp($time); + print "$time: $ip -> $nextip\n"; + } +} -- cgit v1.2.3