Embedded Function for WAN IP Return?
TurnipTruck
Posts: 1,485
Greetings,
Can anyone suggest a way to get the WAN IP address of a network in code? My Netlinx Master is connected to the Internet through a basic router. I am trying to find a way to be alerted if my WAN IP changes. I have i! system monitor out running and can have an email sent to me if my code can be aware of the change. Thanks! This stuff is so much fun!
Can anyone suggest a way to get the WAN IP address of a network in code? My Netlinx Master is connected to the Internet through a basic router. I am trying to find a way to be alerted if my WAN IP changes. I have i! system monitor out running and can have an email sent to me if my code can be aware of the change. Thanks! This stuff is so much fun!
0
Comments
Kevin D.
Here is a snippet of code my module uses for this (modified a bit for simplicity) :
dvConnection is the local device used to make the connection; sIP_Buffer is the port's buffer and I call 'Parse IP Buffer' on a OFFLINE event, because that is how simple HTML connections like this work, they send their data and drop the connection. Note you don't have to actually send anything to the connection, just make it. This only applies to DynDNS's IP service, one using a different HTML variant might require a GET command or something similar. This also assumes the response will be in a form that has the the text "Address: ", followed by the IP number.
In your code, when you SEND_STRING 0, ... where is the string going?
Thanks!
It's most likely for demonstration, you would want to compare the old vs new and do what you need to do.
Kevin D.
Thanks for posting that code. I was playing with it today and had some problems. When I opened the IP_Client it didn't seem like any data was returned at all. I put in some debugging statements in to see if any data was coming in but nothing showed up. If after the connection was opened I sent something like 13,10,13,10 I would then get data back in the form of error messages form the server. I tried changing the website it was pointing to just to see if I could get data going and some worked and some didn't return data.
What I finally ended up doing was finding a website www.webyield.net which uses a CGI Post to return the address. So I open the connection and then send a string with the Post method and parse the incoming data fine.
I am at the office behind a firewall so perhaps thats what is causing the problem with the code you had but thought I'd get your thoughts on it.
Thanks
Andre
I haven't tried it that way - apps I've written that access web servers do something along these lines:
(That snippet is an abbreviation of the code from the DynDNS module I wrote, FWIW)
If you just open a connection to a web server >without< sending an HTTP request of some kind, I didn't think you got any response at all.
- Chip
SEND_STRING dvIP, "'GET / HTTP/1.0',13,10,13,10"
which will return the default document whatever that may be. I've never run across a web server that returned anything without asking for something first.
Joe
First post here, having just discovered this forum. Chip and I have traded ideas a bit from time to time. I have a little module working which does the GET HTTP routine to a website called myipaddress.com every hour. It then compares the IP address it gets with the one it got an hour ago, and if it changed, then it sends me an e-mail. The e-mailing part is crude and clunky but seems to work OK. I just read up about how e-mail works (RFC822) - a standard developed in the 1980s! I was amazed how simple it is.
Here in LA I have dynamic IP DSL from the phone company and sometimes it changes just once every 2-3 days, sometimes 2-3 times a day.
This is the direction I am going. I already have the comparison and email part working. I add the I-Equipment Monitor Out module to most of my systems, including the one I am working on now. All I need is to return the IP address to my code and I'll be good to go.
Another suggestion for people who like to access their system from afar using a dynamic IP address is to use something like I Equipment Monitor In and to send a message to your system to have it reply to you with its IP.
If you have two-way text messaging on your cell phone that can can send and receive with a standard email address, you have one of the most powerful AMX user interfaces.