aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlookshe <lookshe@lookshe-server.(none)>2014-09-21 00:37:43 +0200
committerlookshe <lookshe@lookshe-server.(none)>2014-09-21 00:37:43 +0200
commit7aa21bd2fd75f8949cd6db69db8ba7a801df37b5 (patch)
treeae89a8e1e4f4788712c72b7dec7690638046fff6
parentc4d2aba012967a8636069b723c428622680b969b (diff)
perl script for logging external ip address and analysing changes from its logfile
-rw-r--r--externalIp.pl6
-rw-r--r--ipchanges.pl21
2 files changed, 27 insertions, 0 deletions
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 = <FILE>;
+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";
+ }
+}