more G-Labs products

Author Topic: Managing dynamic IP  (Read 6075 times)

April 02, 2014, 10:04:02 AM
Read 6075 times

jjuel15

  • *
  • Information
  • Newbie
  • Posts: 11
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.

April 03, 2014, 01:38:45 PM
Reply #1

smeghead

  • *
  • Information
  • Newbie
  • Posts: 17
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....

September 05, 2014, 05:15:08 PM
Reply #2

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
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.


September 16, 2014, 05:15:38 PM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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?

September 16, 2014, 07:21:25 PM
Reply #4

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
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 :-)

September 17, 2014, 04:58:59 PM
Reply #5

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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.

September 23, 2014, 12:46:11 AM
Reply #6

Void

  • *
  • Information
  • Newbie
  • Posts: 18
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

September 23, 2014, 12:57:24 AM
Reply #7

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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!

February 16, 2015, 11:00:58 PM
Reply #8

beller

  • *
  • Information
  • Newbie
  • Posts: 24

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?


February 16, 2015, 11:22:46 PM
Reply #9

beller

  • *
  • Information
  • Newbie
  • Posts: 24
founded a fixed automation program, here it is

February 17, 2015, 05:37:22 AM
Reply #10

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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.

March 06, 2015, 04:43:16 PM
Reply #11

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
Since about Feb 12 I am having an issue with the 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.

March 06, 2015, 06:19:52 PM
Reply #12

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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.

March 09, 2015, 12:46:04 AM
Reply #13

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
Thanks, even google responds with this xxxx:xxxxx:xxxx type IP.  :-\  Ah.. its IPv6
« Last Edit: March 09, 2015, 12:49:35 AM by kevin1 »

March 10, 2015, 01:44:08 PM
Reply #14

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
I found that Gene has some similar code that uses json from a different site here:
http://www.homegenie.it/docs/automation_overview.php

This one reports ipv4, so going with that for now.  Thanks Gene :-)