Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Obtaining the IP Address from the Actiontech 1524 DSL Modem
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
svan9420
n00b
n00b


Joined: 24 Apr 2002
Posts: 51

PostPosted: Fri Apr 30, 2004 7:50 pm    Post subject: Obtaining the IP Address from the Actiontech 1524 DSL Modem Reply with quote

A while back, I thought it would be nice to have a script that would send me an email to my work address whenever my IP address changed on my Actiontech 1524 dsl modem. That way, I would always know where I could log into my home machine from work.

Here is the script:
Code:


#!/usr/bin/perl
# ipget.pl- the script that retrieves your IP for you from an actiontec dsl modem model 1524.
# Once the ip is caught, it will email it to whoever is listed in @ToList.
# Run this on the box whose IP you want to figure out. You can make this part of a larger program,
# obviously
#
#Another great use includes adding this to cron
#
# Created by randall svancara
# April 29, 2004
#



use strict;
use LWP::UserAgent;
use Net::SMTP;
use Socket;
use POSIX qw/strftime/;




#########################################################################
# Set the username and password for the actiontech dsl modem
# and email list for new ip address
                                                                                                                                                             
#Login information for the actiontech


my $username = "admin";
my $password = "password";
my $auth_url = "http://192.168.0.1/status_real.html";
my @ToList = qw(bob@somewhere.net bob@somewhere.net);
my $mailrelay = 'mail.private.biz';                                                                                                                         
                                                                                                                                                             
#
# Do not edit below this line
#


# Create new LWP
my $ua = LWP::UserAgent->new;


#Get the request
my $req = HTTP::Request->new(GET => $auth_url);


#Set the request authorization
$req->authorization_basic($username, $password);
                                                                                                                                                             
#Get the data from the request
my $data = $ua->request($req)->as_string;

my $input;
my @section;
my $section;
my $ip;
my $file="/home/pathtoscript/bin/LastIp.txt";
my $logfile="/home/pathtoscript/bin/IPLog.txt";
my $from='somewhere@private.biz';
my $time = strftime( "%B %d, %Y  %r", localtime(time()) );




#
#split up the html document by <tr> tags.  This could have been done more intelligently
#


@section =  split(/<tr/, $data);

#
# For each section, comb through and look for ip address then wan_ip then finally extract out the ip address
                                                                                                                                                             
foreach $section(@section){
  chomp($section);


  if($section =~ /IP Address/){
    if($section =~ /sta_wanip/){
      if ($section =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/){
        $ip = $&;
        open(IPIN,"$file") || die;
        my $tempip=<IPIN>;
        chomp $tempip;

        close(IPIN) || die;


        #if tempip is not equal to ip then we need to take some action
        # Send email alerting all recipients of the change.
        # Update file with new ip address
        if($tempip ne $ip){

          open(IPLOG,">>$logfile") || die;
          print IPLOG $time . " IP Address has changed from " . $tempip . " to " . $ip . "\n";
          close(IPLOG) || die;

          #my $from='someone@somewhere.net';
          # Try to convert ip address to hostname
          my $hostname = gethostbyaddr(inet_aton($ip), AF_INET);
                                                                                                                                                             


          foreach my $to (@ToList)
          {
                my $smtp = Net::SMTP->new($mailrelay, Hello => "mail.private.biz", Timeout => 60, Debug => 0);
                $smtp->mail('someusername');
                $smtp->to($to);
                #$smtp->subject('IP Address Change');


                $smtp->data();
                $smtp->datasend("To: " . $to );
                $smtp->datasend("\n");
                $smtp->datasend("Your computer has been delagated a new IP address.\n");
                $smtp->datasend($ip . "\n");
                $smtp->datasend($hostname . "\n");
                $smtp->dataend();
                $smtp->quit;
                sleep(5);
           }


           open(IPOUT,">$file") || die;
           print IPOUT $ip;
           close(IPOUT) || die;
        }
        #Get the ip address from the file
        #print $ip;
      }
    }
  }
}


_________________
svan9420
Back to top
View user's profile Send private message
dogmeat138
n00b
n00b


Joined: 07 Apr 2004
Posts: 20
Location: Wyoming

PostPosted: Fri Apr 30, 2004 10:23 pm    Post subject: Reply with quote

No clue if the actualy script would work.

If you are just trying to access your machine remotely, but your IP changes, what you should do is setup a dyndns account. You can get free ones from freedns.afriad.org. This site will allow you to setup a subdomain, with a public domain, and use a forward to your ip address, then a script on your machine can be set in cron, to update the up address every hour.
Back to top
View user's profile Send private message
svan9420
n00b
n00b


Joined: 24 Apr 2002
Posts: 51

PostPosted: Sat May 01, 2004 1:45 pm    Post subject: Reply with quote

I guess I like to do things the hard way :(
_________________
svan9420
Back to top
View user's profile Send private message
Boris27
Guru
Guru


Joined: 05 Nov 2003
Posts: 562
Location: Almelo, The Netherlands

PostPosted: Sat May 01, 2004 1:47 pm    Post subject: Reply with quote

You could just set it up to use DynDNS, if it supports that.
_________________
we are microsoft, lower your firewalls and surrender your pc's. we will add your biological and technological distinctiveness to our own. your culture will adapt and service us. resistance is futile.
Back to top
View user's profile Send private message
svan9420
n00b
n00b


Joined: 24 Apr 2002
Posts: 51

PostPosted: Sat May 01, 2004 4:49 pm    Post subject: Reply with quote

Ok, I found some scripts that I can set up with cron here

http://freedns.afraid.org/scripts/freedns.clients.php

I have taken the updateip.pl script and modified it to work with my set up. You just need to use the LWP::simple perl modules to grab the web page where you update your ip address.

Works really good, thanks everyone.

:)
_________________
svan9420
Back to top
View user's profile Send private message
dogmeat138
n00b
n00b


Joined: 07 Apr 2004
Posts: 20
Location: Wyoming

PostPosted: Wed May 12, 2004 11:07 pm    Post subject: Reply with quote

the afraid.org stuff is the same thing as dyndns..
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum