Ideas to find out the IP of my remote PC


PowerGod

Forum Addict!
Joined
Jun 20, 2011
Messages
4,462
At home I have a dynamic address, and for long periods it remains the same because the router is always on, but sometimes if it reconnects the address can change...

In the old times I was using the integrated client for DynDNS (the only service supported by the router), but just because it was free and seemed somehow professional... but now it's not free anymore, so I disabled it.

I prefere to not have a dinamic adress client on my PC, because all the free services I found seems not to be trusted...

So I was thinking about an "e-mail" solution, something like I send a certain kind of mail with the request, and the client on my PC should respond in the same account with a mail containing it's address...

But this should be preferably done on a terminal level, and I have seen many clients, even already installed and standard like "mail".

Anyway with this solution, I'll have to sign in on the mail account, send the mail, and wait for the response... I can do this on different PCs so I can't create some automation for this...

Do you have some better ideas ? Or maybe some way to make this process the most simple possible ?

I'll have to do the request both on Windows and Linux platforms... but my PC at home uses Linux (I don't need this for Windows)
 
Last edited by a moderator:
dont you have a website somewhere?

I assume windows

maybe: use rebol.exe or autoit3.exe to fetch "what is my ip" (several webservices) webpage, scrape the IP address and diff it with a saved version. Upon detection of an IP address change, upload the new IP to a webpage.

here is a MAC/Linux equivalent: http://hints.macworld.com/article.php?story=2004102508055243

and instead of uploading to a webpage, you can change that to email.

(here is a sendmail example)

Code:
http://stackoverflow.com/questions/2282506/how-can-i-send-an-email-through-unix-mailx-command
http://tecadmin.net/ways-to-send-email-from-linux-command-line/
 
Last edited by a moderator:
I've got a bot connected to an IRC channel which I can just log into and give it the command to tell me what its IP address is. It also updates my dyndns when it detects a change in the network but that doesn't always work.

Going back to your original problem though, it is probably possible to update your dynamic IP with a simple wget request. Have a script which periodically (once a minute or five, or every hour) checks what its IP address is, and if it's changed run the appropriate command to do the update. There's probably even a simpler way to figure out that your network has temporarily dropped and then come back though I'm not aware of what it is. My bot is able to because its connected to IRC and as soon as it comes back it runs the wget to update my dyndns.
 
Not sure if Comcast has decided to give out static IP addresses, but mine has been the same for 3 years. I still run dynamic DNS on my router and have a real domain name tied to it just in case it does ever change.
 
Last edited by a moderator:
Maybe I wasn't clear enough, I don't have a domain, I had it when I was using Dyn-DNS because it was one they assigned me, but now I have only the IP.

@flowen8: I'm speaking about the address that the internet provider assign to my router, not the one on the local network. Thanks anyway :)

@FBnil: I'll have to study those scripts... maybe I can do one that sends automatically an email at every IP change, so I don't even have to ask for it, I just check the account and look at the IP written in the last mail :)

TrashyMG: my provider can assign static addresses, but it's a paid service, and actually I like not to have always the same... it gives me the sensation to be anonymous :D LOL

WizardStan and Elw3: didn't thought about irc, cool idea, but I suppose I will need a portable irc client both for windows and linux, and while for windows is a simple thing, I don't know how portable can be a linux client... or maybe I can just use some script, at the end that protocol is terminal friendly... :mellow:  
 
 
Thanks, but maybe later, I want to do some trials with email first before stepping to irc, but this is a new thing for me so it will require some time
 
Yeah, most irc hosts have web interface. If no irc client is available I just hit up the synirc.net webchat. In fact I don't even bother with irc clients anymore, if something has gone wrong with my address I just jump straight to the browser.
 
ddclient does something for you.

cat /etc/ddclient.conf
# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf

protocol=dyndns2
#use=if, if=eth0
use=web, web=myip.dnsdynamic.org
server=dynupdate.no-ip.com

login=bla@blubb.com

password='123'

yourname.ddns.net
 
no-ip let you have a free dynamic DNS, but you have to go onto a webpage every 30 days to prevent deletion. You then run an "updater" app on your PC that constantly checks and uploads your IP to your DynDNS
 
I'll try to avoid the need to have a temporary domain for this purpose.

For now I found a way to know my external IP without asking it to others DNS services or websites (like every googling was telling me to do)...

I just get it from my router, because it already knows it's assigned address :)

This is how I do it from bash:



wget -O status.html --user=<USERNAME> --password=<PASSWORD> http://<ROUTER_IP_ADDRESS>/setup.cgi?next_file=s_status.htm&todo=cfg_init

cat status.html | grep "<td width=\"50%\">" | head -n 8 | tail -n 1 | sed 's/.*>\(\([0-9]\+\.\)\+[0-9]\+\)<.*/\1/'
I just get the IP from the status page of the administration web interface. (My router is a Netgear, but every router should have one)
I'll report my progress for the mail part...
 
Last edited by a moderator:
Ok, seems the mail thing is working :)

At the beginning I tried to send the mail using exim4 (that was already installed), and I configured it pretty fast using the wizard... but gmail was refusing all of them because weren't coming from a domain or a static IP... then I tried to use the gmail SMTP from exim4 but it was becoming a mess of adding things and configurations hell...

So, I tried sSMTP instead ("sudo apt-get install ssmtp" that automatically removed exim4), and found out it was only requiring a very basic configuration to use an external server to send the mail

# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
AuthUser=mymail@gmail.com
AuthPass=gmailpassword
UseTLS=YES
UseSTARTTLS=YES

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=myusername.mydomain

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
#FromLineOverride=YES

Then after this I was ready to ultimate my bash script to check and send the IP

#!/bin/bash
# Get the Status page of the router web interface
wget -O /home/username/status.html --user=USER --password=PASSWORD "http://ROUTER_IP_ADDRESS/setup.cgi?next_file=s_status.htm&todo=cfg_init"

# Get the last saved IP
export routerLastIP=$(cat /home/username/.routerLastIP)
# Get the new IP from the Status page
export routerIP=$(cat /home/username/status.html | grep "<td width=\"50%\">" | head -n 8 | tail -n 1 | sed 's/.*>\(\([0-9]\+\.\)\+[0-9]\+\)<.*/\1/')
rm /home/username/status.html

# Check if the new IP is different from the last
# and in that case it sends the mail, and saves it
if [[ "$routerIP" != "$routerLastIP" ]]; then
mail -s "$routerIP" mymail@gmail.com < /dev/null;
echo $routerIP > /home/username/.routerLastIP
fi

Then the last step, automate the execution of the script every 10 minutes, so for this I used "sudo crontab", because the cron daemon was already installed and ready to work, and I just added the instructions to run my bash

# Checks every 10 minutes if the router IP is changed
00,10,20,30,40,50 * * * * /home/username/routerIP.sh &

and that's all for now, I'll try this configuration for a while, then maybe I'll try even something for irc.

By the way, because the STMP password for the gmail account is in clear on the file, I made another google account just to be used for sending purposes.
 
Last edited by a moderator:
With cron you can save yourself a bit of typing for specifying repeating jobs.. so instead of specifying the specific minutes like you did this works just as well. 

Code:
# Checks every 10 minutes if the router IP is changed
*/10 * * * * /home/username/routerIP.sh &
 
Last edited by a moderator:
Back
Top