LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 02-01-2004, 12:16 PM   #1
Buckyjunior
Member
 
Registered: Jul 2003
Distribution: Kubuntu Hardy
Posts: 76

Rep: Reputation: 15
What's my DHCP assigned IP and where is it?


I would like to set up a cron job to tell me when my ISP changes my IP number.

If my Linux box keeps track of that number somewhere, I could grep it and send myself a message when it changes. All of my computers are behind a router/gateway. The router is controled via internal html pages. I supposed I could write a long script that starts up lynx, loads and saves the page with the IP number and then grep that.

If my Linux box keeps track of that number somewhere, it would be a lot easier.

Any ideas?
Bucky
 
Old 02-01-2004, 12:20 PM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,176
Blog Entries: 4

Rep: Reputation: 430Reputation: 430Reputation: 430Reputation: 430Reputation: 430
ifconfig is the command to find out that sort of thing. It works similarly to Windows ipconfig but is more detailed.
 
Old 02-01-2004, 12:21 PM   #3
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
It would be easier to just wget the html page. Linux doesn't know the external IP of the router, all it cares about is it's IP on the local network and the local IP of the router. Some routers will talk SNMP and notify you when there IP has changed and what it has changed too.
 
Old 02-01-2004, 12:33 PM   #4
Buckyjunior
Member
 
Registered: Jul 2003
Distribution: Kubuntu Hardy
Posts: 76

Original Poster
Rep: Reputation: 15
Thanks for the prompt hint XavierP, but it doesn't _quite_ give the all the information I need.

What I get is the local loopback address (127.0.0.1) and my internal LAN address (192.168.0.110). I don't get my WAN IP.

Thanks for the try.
Bucky
 
Old 02-01-2004, 01:13 PM   #5
Buckyjunior
Member
 
Registered: Jul 2003
Distribution: Kubuntu Hardy
Posts: 76

Original Poster
Rep: Reputation: 15
jtshaw,
That's it. wget

A few tweaks to send user and password, and I've got access to the IP information I need.

There are _so_ many applications in my Linux box (e.g., wget) that I need to find out about. You knew the one I needed. Yesterday I printed out four pages, four columns each, at 8 pt. of apps in bin and sbin (from a2p . . . zprint). I guess I'll make it a project to do --help on each of them to make notes and see which might be of use to me in the future.

Thank jtshaw. I appreciate your help. If anyone is interested, after I follow through, I'll post my script and cron job. I don't imagine that I'm the only one who would like to keep track of their dynamically changing IP addresses.

Bucky

Quote:
Originally posted by jtshaw
It would be easier to just wget the html page. Linux doesn't know the external IP of the router, all it cares about is it's IP on the local network and the local IP of the router. Some routers will talk SNMP and notify you when there IP has changed and what it has changed too.
 
Old 02-01-2004, 02:02 PM   #6
fur
Member
 
Registered: Dec 2003
Distribution: Debian, FreeBSD
Posts: 310

Rep: Reputation: 35
I just read you post and thought this would be a nice thing to have. This is how I just did it..

First I installed sendEmail. This is a lightweight SMTP mail client .

http://caspian.dotconf.net/menu/Software/SendEmail/

Once it is downloaded unzip and untar the file. Then cd into the resulting directory, and copy 'sendEmail' to /usr/local/bin/ .

Then edit 'sendEmail' and change the "Global Variables" to suit your needs.


I then made this bash script.

Code:
#!/bin/bash
cd /home/user/myip
wget whatismyip.org
cat index.html | sendEmail -f you@domain.com -t destination@domain.com
rm index.html

Than just add it to cron.
 
Old 02-01-2004, 03:50 PM   #7
Buckyjunior
Member
 
Registered: Jul 2003
Distribution: Kubuntu Hardy
Posts: 76

Original Poster
Rep: Reputation: 15
fur,
You're fast! GREAT!

I really like the whatismyip.org. It outputs only one text line to grep. When I get things sorted out (i.e., I learn some more), I'll probably do it just a little different.

1) I'll use mail since it is already in the Linux system.
2) I'll compare the whatismyip file with a previously saved IP file
3) Only send myself a message if my IP has changed. (Not knowing sendEmail, you may already be doing this with the -f and -t options.)
4) If it has changed, and I've sent myself a message, then I copy the whatismyip file to the "previously saved IP" file so that I'm not sending myself multiple messages.

Quote:
Originally posted by fur
. . .
I then made this bash script.

Code:
#!/bin/bash
cd /home/user/myip
wget whatismyip.org
cat index.html | sendEmail -f you@domain.com -t destination@domain.com
rm index.html
. . .
Actually, some years ago, I wrote something like this to check for changes in (generally) static web pages. The idea was that when a scheduling page changed, I could automatically send interested users a "This page has changed." message. I can't find what I wrote now and it was never implimented because the computer admin people wouldn't give a graphics person access to crontab. So it goes.

Thanks fur, for the input. Good stuff.
Bucky
 
Old 02-27-2004, 01:29 PM   #8
Buckyjunior
Member
 
Registered: Jul 2003
Distribution: Kubuntu Hardy
Posts: 76

Original Poster
Rep: Reputation: 15
Getting my DHCP assigned IP address

I'm a little slow to follow up, but I think I have what I want. When my ISP changes my DHCP assigned IP address, I will find out about it within 24 hours and can make appropriate reference changes.

I'm guessing that this has all been done before, but as the Perl slogan goes "There's more than one way to do it." I thought that readers here might be in the same situation I am and might appreciate having this little script.

First, I created the subdirectory 'changes' in my home directory, and included the following perl script.
Code:
#!/usr/bin/perl -w
 # script written in perl to see if IP has changed
 # from linuxquestions.org discussion groups
 # written by Buckyjunior 2004/2/26
 
 # set up working directory on Linux box
 chdir "/home/me/changes" or die "cannot chdir to home/me/changes\n: $!";
 
 # uncomment the following line to create the file oldip.txt
 # system touch "oldip.txt";
 
 # get IP address from whatismyip.org as "newip.txt"
 system "wget --quiet --output-document newip.txt whatismyip.org";
 
 # open each file and assign the single line of content to variables
 open (OLD, ' while() {
         chomp($oldip = $_); #get the old file and assign variable
 }
 open (NEW, ' while() {
         chomp($newip = $_); #get the new file and assign variable
 }
 
 if ($oldip ne $newip) {
         # files are different, IP has changed, create newipmsg.txt
         system "cat mailmsg.txt oldip.txt RT.txt newip.txt > newipmsg.txt";
         
         # send mail home with the new IP
         system "mail -n -s 'IP Address Note' -c me\@localhost.localdomain bucky\@anotherISP.com < newipmsg.txt";
 
         # move the new file to become the old file
         system "mv newip.txt oldip.txt";
 
         # remove the "new" file
         system "rm newip.txt";
 }
 
 # no changes, so we don't need to do anything
 # drop out
I saved the file as chkIP. I also wrote a cute text file and named it mailmsg.txt so that I would have something to read in the message in addition to the IP numbers. I couldn't figure out how to insert a carriage return into the cat command, so I created another file RT.txt with a single carriage return.

For the chkIP job, this command and entry made the whole thing work.
Code:
crontab
 37 1 * * *    perl /home/me/changes/chkIP
This was followed by ^D. The crontab entry reads: at 37 minutes into the hour 1, all days of the month, all months of the year, all days of the week, have Perl run the file chkIP in the subdirectory named.

To test it, I made a false IP address for the oldip.txt file and waited overnight for the cron job to run. Works fine. My response looks something like this:

Subject: IP Address Note

Appended below is your old IP address followed by
your new IP address. Please make the appropriate
changes to your system configuration.

cron
123.456.78.90

234.56.789.120


Obviously, if you want to use this code, you'll have to change "me" to whomever you are on your system, make sure you are allowed to run cron jobs, etc.

Enjoy. Be well.
Bucky
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DHCP Server MAC Address found, IP address not assigned wmburke Linux - Wireless Networking 17 11-17-2004 10:33 AM
problem with assigned key y0shi Linux - Wireless Networking 1 10-12-2004 08:39 PM
How do I keep the local name for the computer from being dynamically assigned by DHCP slickrcbd Linux - Networking 3 03-04-2004 12:11 AM
dhcp assigned address nilbog Linux - Networking 4 04-02-2003 11:17 AM
How to find out my IP address on a DHCP IP Assigned machine? simonh Linux - Networking 2 12-10-2002 05:49 AM


All times are GMT -5. The time now is 01:49 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration