Python Plugin: Wan IP Checker

Python and python framework

Moderator: leecollings

User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: Wan IP Checker

Post by ycahome »

iTDB wrote: Sunday 05 April 2020 21:21 It looks like you need to set the Timer to 60 sec, otherwise you will get next error every minute
Error: IP Checker hardware (Idx) thread seems to have ended unexpectedly
Is there a way to set that to 1 or 2 hours without this error.
This is the behaviour of domoticz. Cannot be modified by a plugin.
Bob123bob
Posts: 31
Joined: Monday 09 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Wan IP Checker

Post by Bob123bob »

I made a pull request that fix this issue https://github.com/ycahome/WAN-IP-CHECKER/pull/2
Check changes here : https://github.com/ycahome/WAN-IP-CHECKER/pull/2/files
or
Use my fork instead at https://github.com/gilmrt/Domoticz-WAN- ... ker-Plugin
or
Wait for pull request to be merged and update

The issue was the heartbeat run only at poll interval and must run less that every 30s
I applied recommandations
Warning: Setting this interval to greater than 30 seconds will cause a 'thread seems to have ended unexpectedly' message to be written to the log file every 30 seconds. The plugin will function correctly but this message can not be suppressed because it is a standard warning from Domoticz that a piece of hardware may have stopped responding.
If a plugin wants to heartbeat every 100 seconds it should be coded with the heartbeat interval set to 10, 20 or 25 seconds and only take action every 6th, 5th or 4th time the callback is invoked.
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: Wan IP Checker

Post by ycahome »

Bob123bob wrote: Saturday 02 May 2020 14:38 I made a pull request that fix this issue https://github.com/ycahome/WAN-IP-CHECKER/pull/2
........

Your Pull Request has been merged. regards.


Current version:
v.1.2.6 : Fix (by gilmrt) for "Error: IP WAN hardware (XX) thread seems to have ended unexpectedly"
pe1ago
Posts: 4
Joined: Saturday 25 January 2020 12:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Plugin - Wan IP Checker

Post by pe1ago »

andi216 wrote: Wednesday 30 August 2017 16:37 Hello
How can I send a notification to the Telegram if it changes wan ip?
(A simple method ... I'm not a programmer)
Same question here. Is there already a solution to send a Telegram message?
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Plugin - Wan IP Checker

Post by ycahome »

pe1ago wrote: Monday 01 November 2021 16:09
andi216 wrote: Wednesday 30 August 2017 16:37 Hello
How can I send a notification to the Telegram if it changes wan ip?
(A simple method ... I'm not a programmer)
Same question here. Is there already a solution to send a Telegram message?
I didn't had the chance to test it but, I think that if you set telegram's settings at Setup/Settings/Notifications/Telegram and enable Notifications on th plugin, you will get a notification for every WAN ip change. I personally receive it by email.

Actually, plugin uses Domoticz's notification settings.

regards,
pe1ago
Posts: 4
Joined: Saturday 25 January 2020 12:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Wan IP Checker

Post by pe1ago »

First Thanks. That works but it will not sent the new WAN ip address only a change message.
I like to get the IP so I now how to get back into domoticz without the need for a DDNS.
Any chance? :roll:
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: Wan IP Checker

Post by ycahome »

pe1ago wrote: Thursday 11 November 2021 15:12 First Thanks. That works but it will not sent the new WAN ip address only a change message.
I like to get the IP so I now how to get back into domoticz without the need for a DDNS.
Any chance? :roll:
Hello,

what this plugin is designed to do (with "notify" enabled) is to send an email with:
- subject "WAN-IP-Changed"
-body the new WAN IP address.

can you post here what you receive?
pe1ago
Posts: 4
Joined: Saturday 25 January 2020 12:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Wan IP Checker

Post by pe1ago »

I have personal reasons not to work with email on Domoticz, al do it works that way.
I love to receive a telegram with the new IP. If possible of coarse.
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: Wan IP Checker

Post by ycahome »

pe1ago wrote: Thursday 11 November 2021 16:19 I have personal reasons not to work with email on Domoticz, al do it works that way.
I love to receive a telegram with the new IP. If possible of coarse.
You have sent 4 posts to this forum.
in 1 of them you mention that the message you get "not contains the WAN IP"
on another you say that you don't want to use email but telegram.

cannot imagine what are the other two posts :lol: :lol: :lol: :D :roll: :o

Maybe you can try to search awhile before you post.
Start with some tests to see how notification system of Domoticz really works (its only 4 posts above after all)
Hesmink
Posts: 168
Joined: Monday 22 June 2015 10:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Python Plugin: Wan IP Checker

Post by Hesmink »

Is there any way to force the checker to request only for ipv4?

I now get an ipv6 address from https://ifconfig.me/ip
Hesmink
Posts: 168
Joined: Monday 22 June 2015 10:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Python Plugin: Wan IP Checker

Post by Hesmink »

Hesmink wrote: Friday 19 January 2024 20:42 Is there any way to force the checker to request only for ipv4?

I now get an ipv6 address from https://ifconfig.me/ip
To answer my own question: https://ipv4.icanhazip.com
lost
Posts: 659
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Wan IP Checker

Post by lost »

Hesmink wrote: Friday 19 January 2024 20:48 To answer my own question: https://ipv4.icanhazip.com
Not using this plugin, but from a lua time script that checks for changes periodically (stores them in a user var & if changed sends a mail with info+access links or at least once a week) I use theses URLs to get both:

https://api.ipify.org
https://api64.ipify.org

IPv6 can also be retrieved direcly from machine interface /sbin/ifconfig or similar tool as this one is global, but using external URLs allows checking true connectivity is OK & make both checks the same. IPv6 should almost never change are providers prefixes are not.

IMO, that's useful to get both: Already being compelled to use some hot-spots AP that were not under my control (hotels etc, especially in foreign countries where mobile phone network could also not be used) with no more available DHCP leases for hours due to heavy use by many people: So no IPv4 connectivity. But ipV6, addressing being global, could be used and having the address needed as in such case DNS may also be affected by lack of IPv4 (external port filtered in AP configuration), so no domain usable.

=> My advice: Don't choose, get both & in a way that may be used offline if needed (mail client that keep already loaded messages locally)!
Cdzn
Posts: 18
Joined: Monday 02 March 2020 10:09
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: Wan IP Checker

Post by Cdzn »

Hi guys. This method does`t work anymore?
viewtopic.php?t=14489&sid=03c00c6ca0ceb ... 1dc0c1cc57
Fredom
Posts: 140
Joined: Saturday 19 September 2020 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Krimpen aan den IJssel
Contact:

Re: Python Plugin: Wan IP Checker

Post by Fredom »

Cdzn wrote: Friday 22 November 2024 11:49 Hi guys. This method does`t work anymore?
viewtopic.php?t=14489&sid=03c00c6ca0ceb ... 1dc0c1cc57
This wan works for me for years now

Code: Select all

return {
	on = {
		timer = { 'every 1 minutes' }
	},

	logging = {
		level = domoticz.LOG_FORCE,
		marker = '[WAN IP]'
	},

execute = function(dz, devNil)

	local dzb = dz.LOG_FORCE
	local getIp = 'curl -s http://whatismyip.akamai.com/'
	local tmpFile = '/home/your name/domoticz/scripts/wanip.txt'
	local actIp = ''
	local devIp = dz.devices('WAN IP')
	local currIp = devIp.text

	os.execute(getIp..' > '..tmpFile)
	actIp = io.open(tmpFile):read()

	if actIp == nil then
		actIp = 'Cannot retrieve WAN IP'
	end

	if actIp ~= currIp then
		msgTxt = 'WAN IP has changed: '..currIp..' ==> '..actIp
		dz.log(msgTxt, dzb)
		dz.notify('WAN IP', msgTxt, dz.PRIORITY_EMERGENCY)
		devIp.updateText(actIp)
		os.execute('rm '..tmpFile)
	else
		dz.log('No change in WAN IP', dzb)
	end
end

}

Don't forgot not to chance in this line your name
Yours sincerely,
Fred

Rasberry Pi 3B+ - Debian Buster - Domoticz 2022.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
User avatar
dyter
Posts: 42
Joined: Thursday 08 February 2018 15:48
Target OS: NAS (Synology & others)
Domoticz version: 8841
Location: Lyon
Contact:

Re: Python Plugin: Wan IP Checker

Post by dyter »

I create a device "Ping Internet" for alert if internet down or wan changed

Code: Select all

commandArray = {}
if devicechanged['Ping Internet'] then
    time = os.date("%H:%M")
    if devicechanged['Ping Internet'] == 'On' then
        commandArray['SendNotification']= 'Internet maison rétablit à '..time..'#####telegram'
        local function get_ip(url)
            local result = (io.popen('curl -m 1 -s ' .. url):read("*a")):match("%d+%.%d+%.%d+%.%d+")
            return result
        end
        ipwan = get_ip('https://api.ipify.org') or get_ip('https://icanhazip.com') or get_ip('https://ifconfig.me')
        print(ipwan or "Erreur")
        if ipwan ~= uservariables["ipwan"] then
            commandArray['Variable:ipwan']= ipwan
    	    commandArray['SendNotification']= 'Attention adresse WAN changée: '..ipwan..'#####telegram'
        end
    	if otherdevices['Escaliers'] == 'On' then
    		commandArray['Escaliers']='Off'
    	end
    elseif devicechanged['Ping Internet'] == 'Off' then
    	if (time < '08:00' or time > '19:00') and otherdevices['Alarme'] == "En service" then
    		commandArray['Escaliers']='On'
    	end
    end
end
return commandArray

Domoticz v2024.1 on Synology Docker host, RFLink, ESPEasy wemos D1, Ecodevices, relays x8, dahua doorbell, reolink cameras ....
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Python Plugin: Wan IP Checker

Post by sincze »

Hesmink wrote: Friday 19 January 2024 20:48
Hesmink wrote: Friday 19 January 2024 20:42 Is there any way to force the checker to request only for ipv4?

I now get an ipv6 address from https://ifconfig.me/ip
To answer my own question: https://ipv4.icanhazip.com
Thanks that helped ;-) I was trying the "-4 ifconfig.me" way but that did not work out ;-)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest