Skip to content

Instantly share code, notes, and snippets.

Created July 6, 2015 13:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Script that takes the current IP address of a server and updates its record with Google Domains
#!/usr/bin/env perl
use strict;
use warnings;
use HTTP::Request;
use LWP::UserAgent;
use Regexp::Common qw /net/;
use JSON;
use Socket;
my $username = '<FILLME>';
my $password = '<FILLME>';
my $hostname = '<FILLME>';
my $ua = LWP::UserAgent->new;
# Get the current external IP according to
my $ipreq = HTTP::Request->new(GET => '');
my $ipres = $ua->request($ipreq);
my $ip = '';
if ($ipres->is_success) {
if ($ipres->content =~ /$RE{net}{IPv4}{-keep}/) {
$ip = $1;
else {
die ($ipres->content);
my $address = inet_ntoa(inet_aton($hostname));
# Print the time so we have a point of reference
print time() . "\n";
unless ($address =~ $ip) {
my $api = "${hostname}&myip=$ip";
my $req = HTTP::Request->new(GET => $api);
$req->authorization_basic($username, $password);
my $res = $ua->request($req);
if ($res->is_success) {
print $res->content . "\n";
else {
die ($res->content);
else {
print "No update needed\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment