Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Sep 2003 23:23:03 +0100
From:      merv <merv@merv.org.uk>
To:        "Drew Tomlinson" <drew@mykitchentable.net>, "FreeBSD Questions" <freebsd-questions@freebsd.org>
Subject:   Re: How to Get Public IP From LinkSys Router?
Message-ID:  <200309032323.03378.merv@merv.org.uk>
In-Reply-To: <019101c37248$ffd50c30$6e2a6ba5@lc.ca.gov>
References:  <019101c37248$ffd50c30$6e2a6ba5@lc.ca.gov>

next in thread | previous in thread | raw e-mail | index | archive | help
Drew,

I use a perl script to get mine, see below. It may point you in the right 
direction. You will need to change this script to use your SMTP server, your 
email address and the IP address of your router.

~~~

#!/usr/bin/perl
# Dynamic DNS, style program. 
# 
# Usage : Ask the Router for my Dynamic WAN IP addres and 
#         then mail the result to me.
#
# Future : Build HTML page and post it to my Web site.
#
# perl -MCPAN -e 'install Bundle::LWP'
#
use LWP::UserAgent;
use HTTP::Cookies;
use Net::SMTP;

#
# Send Mail to Me with my IP address.
#

#Array of people to tell
@ToList = qw(my_addr@somplace.com
	     another_user@somplace.com
	    );


sub send_mail()
{
	$from="FreeBSD";
	$srvr="<YOUR SMTP SERVER>";

	$smtp = Net::SMTP->new($srvr);

	foreach $to (@ToList)
	{ 	
		$smtp->mail($from);
		$smtp->to($to);

		$smtp->data();
		$smtp->datasend("To: Users\n");
		$smtp->datasend("\n");
		$smtp->datasend("New IP address is :". $ip . "\n\n");
		$smtp->dataend();
		
		sleep(1);
	}
	   
	$smtp->quit;
}


#What was the IP address last time, we will save and check.
$in_file = "h:/wsh/WANIP_LOG.txt";
$out_file = "h:/wsh/WANIP_LOG.txt";

$linksyspassword = '<NOT TELLING YOU>';
$ua = new LWP::UserAgent;

$req = new HTTP::Request GET => 'http://<ROUTER'S IP>/Status.htm';
$req->authorization_basic('',$linksyspassword);

$res = $ua->request($req);
if ( $res->is_success ) 
{  
	@data = split /<tr>/, $res->as_string; 
}
else 
{ 
#	print "Error: unable to get router's address\n";
	exit 1;
}

foreach $data (@data)
{
	if ( $data =~ /IP Address:/ )
  	{ 
   	$data =~ s/<\/td><\/tr>//g;     # trim extraneous tags
   	$data =~ s/<(.)*>//;		   # 	
   	$ip = $data;                    # The second IP is what we want.
  	}
}

#Read in Old WAN IP.
open (IN, "<$in_file") || die "Can't open $in_file: $!\n";
undef $/;      #Skip end of line marker.
$content = <IN>;
close(IN);
$/ = "\n";     #Restore for normal behaviour later in script

if(($content =~ m/$ip/)==0) 
{
	send_mail();
}

#Save the WAN IP
open(OUT, ">$out_file") || die "Can't open $in_file: $!\n";
print OUT "$ip\n";


#print "DSL Gateway $ip \n";





On Wednesday 03 September 2003 7:27 pm, Drew Tomlinson wrote:
> I need to get my public IP address from a LinkSys cable router and don't
> have any idea where to start.  The LinkSys is doing NAT and my FBSD box
> in on the private network on the inside.  What commands and/or ports are
> there that would provide the public IP address from the command line so
> I pass the IP to a script?  Any ideas?
>
> Thanks,
>
> Drew
>
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200309032323.03378.merv>