# Getting my gentoo box to report my Routers Ip remotely

## lowbatt

Title says alot of it.

I have a DSL connection and a Dlink I-704 router. It is a pppoe connection and if I need to reboot it or it gets disconected The Ip changes. I was wondering if anyone knows a way that I can get my gentoo box to check that up then report it to me by email. 

Anyone have any ways to do this?

----------

## ghost_o

 *lowbatt wrote:*   

> Title says alot of it.
> 
> I have a DSL connection and a Dlink I-704 router. It is a pppoe connection and if I need to reboot it or it gets disconected The Ip changes. I was wondering if anyone knows a way that I can get my gentoo box to check that up then report it to me by email. 
> 
> Anyone have any ways to do this?

 

You could write a Perl script that uses LWP to go here:

http://www.ostrosoft.com/OIT/GetExternalIP.asp

Or you could go to gotdns.org and download a pre-existing script that will work with your Dlink router.

-G

----------

## rojaro

i had basically the same problem when i wanted a lean and clean way to verify that my ods.org dynamic host name remains correct even if my ipaddress changes.

so here is what i did:

i created a simple one line php script which is running on my website (which is hosted at a regular provider - not at home on my machines) and named it whoami.php:

```
<?php echo $_ENV["REMOTE_ADDR"]; ?>
```

of course you could skip that step and use the url proposed by ghost_o above in the next step instead.

on my machine at home i created a very simple shellscript (/home/rojaro/bin/odsupdate) which uses the GET script from the perl lwp package, but you could also use wget or lynx instead. it looks like this

```
#!/bin/bash

WHOAMI=`/usr/bin/GET http://website/whoami.php`

OLDDNS=`/usr/bin/host mydomainname.ods.org | /bin/sed -e 's/mydomainname\.ods\.org has address//'`

if [ $WHOAMI == $OLDDNS ] ; then

  echo "mydomainname.ods.org is still online at $WHOAMI"

else

  RESULT=`/usr/local/bin/odsclient username password mydomainname.ods.org`

  echo $RESULT

fi
```

so as you can see the script first asks the webserver on what it sees as my ip address. then it looks up the ipaddress which is registered to my ods.org domainname (e.g. mydomainname.ods.org). so if the results are diffrent, we need to run the odsclient.

finally i added a line to my local crontab that triggers the script every five minutes

```
*/5 * * * * /home/rojaro/bin/odsupdate
```

as i dont care pretty much about any occuring problem when the script is ran from the crontab i also added " > /dev/null" to that line so crontab would not send me emails with the script output as it will update the ip-address automatically (so i dont have to do anything at all).

i assume you've pretty much got the same problem :)

----------

## rphillips

How about using a dynamic DNS?  ddclient and dyndns.org work great together, and setting the IP of your router isn't a problem...

----------

## rojaro

 *rphillips wrote:*   

> How about using a dynamic DNS?  ddclient and dyndns.org work great together, and setting the IP of your router isn't a problem...

 

you didnt read my post and the original question ... didnt you?

----------

## lowbatt

Ok i got the dynamic DNS all set up. My last question is is there a good way to set the local script on the machine to run as a cron job every lets say 15 min? I've never worked with cron jobs before. I will go do some searching but i just wanted to see what you guys say.

----------

## rojaro

well, i placed the odsclient into /usr/local/bin as i compiled it myself (without using portage in any way) and the client is just a normal 08-15 tool which should be available to all local users. as the odsupdate script also contains the username and password in clear text i placed it inside my homedirectory where i have a bin directory (/home/rojaro/bin) only for myself (for tools no one else except root can access as my homedirectory is also mode 0700) which i also have in my path evironment ("export PATH=$PATH:~/bin" in .bashrc).

----------

