Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple check my ip address script help?

Status
Not open for further replies.

Bjoeboo

Technical User
Nov 5, 2008
2
US
I need to give somebody my ip address so they can add it to their whitelist for access but the trouble is my ip address (the real internet facing one, one not the internal dhcp one) keeps changing every so often. So I want to capture them as they change. I think there's only 2 or 3 of them that the ISP rotates us through (I see the same 2 or 3 repeatedly) but I'm not sure.

I use XP, I've got Activestate installed and I'm trying to create a simple script that I can put in Task Scheduler to run each day that will check and append the data to the same file each day.

Please help.
 
Can you give them a dyndns name and just use that? You can use LWP to get the information from the web page.. do you have a router or can you get the information directly off of your PC?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I actually have a script that does exactly this. My home IP only changes when the modem resets (power outage, etc.) and I have a domain name that points to it, but every now and then I'm away from home and try to connect to find out my IP has changed. So this script checks that page once every hour and every time the IP changes, it calls a CGI script on my VPS webserver so I can always go there and find out what my IP is when the domain name doesn't match anymore.

Here:

Code:
[kirsle@epsilon bin]$ cat whatsmyip 
#!/usr/bin/perl -w

use strict;
use warnings;
use LWP::Simple;
use Mail::Sendmail;

my $ip = '';
my $lastcheck = 0;

# fork
my $pid = fork();
die "forking as $pid" if $pid;
close(STDOUT);
close(STDERR);
close(STDIN);

# Get our IP.
while (1) {
   if (time() > $lastcheck) {
      print "Checking IP address\n";
      my $newip = get "[URL unfurl="true"]http://www.whatismyip.com/automation/n09230945.asp";[/URL]
      print "Got: $newip (had: $ip)\n";

      if ($newip ne $ip) {
         # Update it
         my $echo = get "[URL unfurl="true"]http://domain/homeip.pl?ip=$newip";[/URL]
         $ip = $newip;
         $lastcheck = time() + 3600;
      }
   }
   sleep 60;
}

You can ignore the forking stuff there if you don't need it. The key part here is LWP::Simple and the main while loop (forking won't work on Win32 systems iirc).

-------------
Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top