Skip to content

Instantly share code, notes, and snippets.

@JohnMertz
Created May 28, 2020 19:19
Show Gist options
  • Save JohnMertz/d9d40214e524a7de09184ec57b3baeda to your computer and use it in GitHub Desktop.
Save JohnMertz/d9d40214e524a7de09184ec57b3baeda to your computer and use it in GitHub Desktop.
Is a device currently up on LAN (determine if my phone is at home).
#!/usr/bin/perl
use strict;
use warnings;
use Net::Ping;
my $file = "/tmp/amihome";
my $host = "192.168.2.127";
my $current;
if ( -r $file ) {
open( my $in, '<', $file ) || die "Can't open existing file\n";
while (<$in>) {
chomp($_);
$current = $_;
}
close($in);
}
my $p = Net::Ping->new();
my $new = $p->ping($host);
$p->close();
print $new . "\n";
unless (defined($current) && $current == $new) {
open( my $out, '>', $file ) || die "Can't open output file\n";
print $out $new;
close $out;
# Copy to server
`scp -i /root/.ssh/no_pass /tmp/amihome jpm\@10.8.0.1:/tmp/new_amihome`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment