Skip to content

Instantly share code, notes, and snippets.

@JohnMertz

JohnMertz/amihome.pl

Created May 28, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.