Results 1 to 4 of 4

Thread: Finding out when IP address changes but network remains the same

Hybrid View

  1. #1

    Finding out when IP address changes but network remains the same

    Hello!
    I am using Ubuntu 10.04 and when I am connected to my preferred automatic network, my computer is assigned a new IP address every so often without me, the user, needing to be aware of it. I have no control over the network server, just my own computer. Here's my goal:
    I'm looking for a way to detect whenever my IP address has been changed, and to record my new IP address in a text file. I could use Linux Scheduling for this, I know, but then I would have to bog up my computer with an extraneous process that would execute every 5 mins or so to make sure I catch the IP change close to when it happens. My IP doesn't change that often - sometimes I go days with the same address, so I'm hoping that there is some sort of networking script that executes whenever my computer is assigned a new IP address. Then I would modify the end of that script to run my own script that keeps track of the IP address.

    So: Is there such a script that runs each time I receive a new IP address? Or, are there better suggestions for doing this?

    Thanks very much, and if you'd like more information about what I'm trying to do, just let me know.

    -Khiya

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    I dont know about Ubuntu, but with Debian and using dhcpclient, it is just to place a script in /etc/dhcp/dhclient-enter-hooks.d/ something like:
    Code:
    echo "${new_ip_address}" >> /some/where/my_file
    Else if it is supposed to happen when te external interface is beeing initiated, place a script in /etc/network/if-up.d/ something like:
    Code:
    echo "${IF_ADDRESS]" >> /some/where/my_file
    Again this is on a ddebian install, I dont know if Ubuntu provides the same functionality, but since it is derived from teh debian architecture it might.
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

  3. #3
    Thanks, Redhead, apparently Ubuntu is enough like Debian for what I need to do!
    However, simply saving a script in the dhclient-enter-dhooks.d or if-up.d folders wasn't enough (I'm not sure if you meant to imply that it would be - I assumed that because I'm new to linux). So I just piggybacked my line of code (simply ifconfig | grep "inet addr:" > path/to/my.file ) on the file named upstart in the if-up.d folder and now every time I change networks, my.file gets re-written with the line containing my IP address. That's all I needed!

    Regards,

    Khiya

  4. #4
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    What I ment to imply was that, atleast in deian, theres an internal variable which is beeing set so ie. when placing the script in /etc/network/if-up.d/ you will get the IP addres when requesting $IF_ADDRESS but it could be Ubuntu has changed that, either way using the internal variable or your approach will get the same result the point is the scripts beeing placed in those directories will get run when the system detects changes to the interface, which is the triggerpoint you were looking for.
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

Similar Threads

  1. setting static IP on network with no static IP address from internet provider?
    By solvetek in forum Linux - Hardware, Networking & Security
    Replies: 4
    Last Post: 11-16-2011, 07:23 AM
  2. How to Achive IP address through MAC(Ethernet) address
    By krishnacins in forum Linux - Hardware, Networking & Security
    Replies: 3
    Last Post: 10-03-2005, 02:17 PM
  3. Finding ALL network settings and NIC info
    By caligal in forum Linux - General Topics
    Replies: 4
    Last Post: 08-31-2005, 03:43 PM
  4. Finding my REAL ICS Client IP address
    By frankietomatoes in forum Linux - Hardware, Networking & Security
    Replies: 1
    Last Post: 10-20-2002, 08:08 PM
  5. Finding Problems
    By Ashcrow in forum Linux - Hardware, Networking & Security
    Replies: 11
    Last Post: 04-08-2002, 12:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •