#!/usr/bin/perl # # SSL Client for DtDNS Version 1.0 06/01/01 # SSL Client for DtDNS Version 1.2 11/25/02 # R.W. (Bob) Hughes # Modified to check against nslookup by Kevin Killingsworth # ver 1.2 added test for "not valid" hostname # # To add Net::SSLeay # perl -MCPAN -eshell; # cpan> install Net::SSLeay #======================================================================== require 5.004; use Socket; use Net::SSLeay qw(die_now die_if_ssl_error); use Sys::Hostname; use strict; #======================================================================== if ($#ARGV < 0) { print "\nUsage:\n\n"; print " $0\t\tPrints this screen\n"; print " $0 up\tSends our current IP\n"; print " $0 down\tSends 0.0.0.0 to put this host off line\n"; print " $0 sync\tChecks NS IP against current IP and updates if needed\n"; exit(1); } #======================================================================== # # You will need to change these as needed # my $DtDNS_hostname="hostname"; # Your DtDNS hostname my $DtDNS_passwd="yourpassword"; # Your DtDNS password my $DtDNS_domain="slyip.net"; # Your DtDNS domain my $Ext_port="ppp0"; # Your Interface to the Big I #======================================================================== my $remote = 'www.dtdns.com'; my $port = 443; #======================================================================== # # Set the IP to either the IP of the Internet facing Interface or 0.0.0.0 # for off line notification, or check to see if they match and then # set if they don't. # # # Get the External IP # (the real IP) # my ($My_ip); my $ip = `/sbin/ifconfig $Ext_port`; $ip =~ /.*inet addr:([0-9\.]*)\s.*/; $My_ip = $1; print "External IP is $My_ip\n"; # # Get the NameServer IP # (what the NameServer thinks the real IP is) # my ($My_nsip); my $nsip = `host $DtDNS_hostname.$DtDNS_domain`; $nsip =~ /.*has address ([0-9\.]*)\s.*/; $My_nsip = $1; print "NameServer IP is $My_nsip\n"; # # Now see what we need to be doing... # my $ToDo = shift(@ARGV); $ToDo =~ tr/A-Z/a-z/; if ($ToDo eq 'up' or $ToDo eq 'sync') { if ($My_ip eq $My_nsip) { # Do nothing, we've got everything right... print "NameServer IP is current.... Exiting\n"; exit; } else { # Updatedate it... print "NameServer IP is out of date, updating...\n"; } } elsif ($ToDo eq 'down') { $My_ip = "0.0.0.0"; # Set the ip to 'offline'... } else { print "The options are \"up\", \"down\" or \"sync\".... Exiting\n"; exit; } #======================================================================== # # Message to send # my $msg="GET /api/autodns.cfm?id=$DtDNS_hostname&pw=$DtDNS_passwd&ip=$My_ip HTTP/1.1\nHost: www.dtdns.com\nUser-Agent: Hugheshut-ssl\n\n"; #======================================================================== # # Strict likes these # my ($iaddr, $paddr, $ctx, $ssl, $res, $got); #======================================================================== Net::SSLeay::load_error_strings(); Net::SSLeay::SSLeay_add_ssl_algorithms(); Net::SSLeay::randomize(); if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') } die "No port" unless $port; $iaddr = inet_aton($remote) or die "No host: $remote"; $paddr = sockaddr_in($port, $iaddr); print "Contacting DtDNS for update...\n"; socket(S, &AF_INET, &SOCK_STREAM, 0) or die "Can Not create Socket: $!\n"; connect(S, $paddr) or die "Can not connect to DtDNS: $!\n"; select(S); $| = 1; select(STDOUT); $ctx = Net::SSLeay::CTX_new() or die_now("Failes to create SSL_CTX $!"); Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) and die_if_ssl_error("ssl ctx set options"); $ssl = Net::SSLeay::new($ctx) or die_now("Failed to create SSL $!"); Net::SSLeay::set_fd($ssl, fileno(S)); $res = Net::SSLeay::connect($ssl) and die_if_ssl_error("ssl connect:"); # # Informational # #print "Cipher '" . Net::SSLeay::get_cipher($ssl) . "'\n"; # Now Write the message $res = Net::SSLeay::write($ssl, $msg) or die_if_ssl_error("ssl write"); #print "Shutting down Socket\n"; shutdown S, 1; while (1) { $got = Net::SSLeay::read($ssl) or die_if_ssl_error("ssl read"); if ($got=~/Host / or $got=~/not valid/) { print "$got\n"; last; } } Net::SSLeay::free ($ssl); Net::SSLeay::CTX_free ($ctx); close (S) or die "close: $!"; exit;