HomeGenie Forum

Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started by: jjuel15 on April 02, 2014, 10:04:02 AM

Title: Managing dynamic IP
Post by: jjuel15 on April 02, 2014, 10:04:02 AM
Hi

I?m using HG on an PI, having internet connection with a dynamic IP (fixed IP would increase the monthly fee for the connection).

This could potentially mean that a loose contact to HG when out of the house, in case that the IP should change.

To cope with this (and using some other contributions around the site, thanks!), I have made this little C# program, which check the external IP every hour and send me a mail, in case the IP changes.

When initiating the program it assumes that the IP is empty, so it will also send a mail when starting, and that way if HG or the PI is has been restarted (that way I will also get a mail if power fails and returns).

Hope this can be a help for others, or inspire new programs.
Title: Re: Managing dynamic IP
Post by: smeghead on April 03, 2014, 01:38:45 PM
Hi jjuel15,

Thanks for this, could be useful. The alternative is to register with a dynamic DNS provider such as http://www.noip.com/

You would need to install a small utility that you can download to keep the DNS provider updated but essentially you get a static IP with a proper domain name that you can create.

Hope this helps, just a different way to do it....
Title: Re: Managing dynamic IP
Post by: kevin1 on September 05, 2014, 05:15:08 PM
Thanks for this!   I had to comment out the file stream writer to get it to work on Win7.  It threw exception that appeared to be the WebService when that actually was working and reporting my IP.

Title: Re: Managing dynamic IP
Post by: bkenobi on September 16, 2014, 05:15:38 PM
I'm using this code now and it seems to work fine most of the time.  For some reason once in a while HG thinks my IP is blank.  As a result, it's emailing me once to let me know it was something and has changed to nothing.  Then, an hour later, it emails to let me know it's set back to what it was.  I assume this is a connectivity issue (HG can't contact trackip.net for some reason).  Has anyone else seen this?
Title: Re: Managing dynamic IP
Post by: kevin1 on September 16, 2014, 07:21:25 PM
I have been running this for about a week and a half and I haven't noticed this.  My IP hasn't changed from my provider, but I do get the SMS when I restart HG... so I think it is working :-)
Title: Re: Managing dynamic IP
Post by: bkenobi on September 17, 2014, 04:58:59 PM
I am running a slightly updated/modified version of the code, but that shouldn't affect this issue.  Not knowing the cause, I found a simple way to trap the blank IP from being processed.  I changed
Code: [Select]
if (ipdata != Program.Parameter("ip").Value)to
Code: [Select]
if (ipdata != Program.Parameter("ip").Value && ipdata.Length>6)
Since an IP is formatted as xxx.xxx.xxx.xxx and each number can be as short as 1 character, the minimum length of the string if valid is 7.  There are more robust ways to check this, but I think this should work for the current issue.
Title: Re: Managing dynamic IP
Post by: Void on September 23, 2014, 12:46:11 AM
If somebody is interested, i can clean and publish here my NoIP DynDNS HG update client (Everything done from HG, no external programs needed).  :D
Title: Re: Managing dynamic IP
Post by: bkenobi on September 23, 2014, 12:57:24 AM
I haven't used those services since I haven't valued this enough to pay for the capability (not running any real web servers so no need).  I suspect that code would benefit some people right now, and I may switch to that approach down the road anyway!
Title: Re: Managing dynamic IP
Post by: beller on February 16, 2015, 11:00:58 PM

anybody allowed to fix this json response problem ?

this program is not working for me, maybe that website have changed the response, here is a example of the current response posted in web browser:

{"ip": "83.123.219.28", "latlong": "45.465454,9.186516", "country": "IT", "city": "milan", "user-agent": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36"}

how to extract the current ip?

Title: Re: Managing dynamic IP
Post by: beller on February 16, 2015, 11:22:46 PM
founded a fixed automation program, here it is
Title: Re: Managing dynamic IP
Post by: bkenobi on February 17, 2015, 05:37:22 AM
That is a somewhat modified version of the original code provided on the forum.  I'm not going to take credit for the original certainly.  But, I find the updates useful.
Title: Re: Managing dynamic IP
Post by: kevin1 on March 06, 2015, 04:43:16 PM
Since about Feb 12 I am having an issue with the http://www.trackip.net/ip. (http://www.trackip.net/ip.) it is reporting what looks more like a MAC address xxx:xxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx rather than an IP xx.xx.x.xxx.  Anyone else seen this?  My PC is behind AT&T Uverse Gateway/router and HG seems to be functioning fine otherwise.
Title: Re: Managing dynamic IP
Post by: bkenobi on March 06, 2015, 06:19:52 PM
I just checked and accessing "http://www.trackip.net/ip" as is indicated in the script returns a single line containing an IP address formatted correctly.
Title: Re: Managing dynamic IP
Post by: kevin1 on March 09, 2015, 12:46:04 AM
Thanks, even google responds with this xxxx:xxxxx:xxxx type IP.  :-\  Ah.. its IPv6
Title: Re: Managing dynamic IP
Post by: kevin1 on March 10, 2015, 01:44:08 PM
I found that Gene has some similar code that uses json from a different site here:
http://www.homegenie.it/docs/automation_overview.php (http://www.homegenie.it/docs/automation_overview.php)

This one reports ipv4, so going with that for now.  Thanks Gene :-)
Title: Re: Managing dynamic IP
Post by: petediscrete on May 10, 2016, 10:30:46 PM
Just wondering if this program still working. Using the modified version, link posted by beller, and getting no notification of change in IP address. I've no problem receiving email from HG as alarm email notification is working fine.
Title: Re: Managing dynamic IP
Post by: nolio on May 12, 2016, 08:52:31 PM
I have just tried on my side now, and it work by changing the Path to log file to /tmp/ip.log.
With the default one /usr/local/bin/homegenie/log/ip.log, it seems that HG can create the file ip.log ....
Title: Re: Managing dynamic IP
Post by: petediscrete on May 14, 2016, 02:57:28 PM
Good man Nolio. Problem solved and program running now. Well done.