diff --git a/fhem/CHANGED b/fhem/CHANGED index f1462b6b9..63398d1fb 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: global dnsHostsFile attribute added (Forum #78025) - feature: 98_DOIFtools: add getter hsvColorGradient, returns a table of value, colornumber, RGB values and color bar using Color::hsv2rgb - new: 46_TeslaPowerwall2AC: retrieves data from a Tesla Powerwall 2AC diff --git a/fhem/FHEM/HttpUtils.pm b/fhem/FHEM/HttpUtils.pm index 5457adf8a..820da7a04 100644 --- a/fhem/FHEM/HttpUtils.pm +++ b/fhem/FHEM/HttpUtils.pm @@ -214,6 +214,24 @@ HttpUtils_gethostbyname($$$$) if($HU_dnsCache{$host} && $HU_dnsCache{$host}{TS}+$HU_dnsCache{$host}{TTL} > gettimeofday()); + my $dh = AttrVal("global", "dnsHostsFile", "undef"); + if($dh) { + my $fh; + if(open($fh, $dh)) { + while(my $line = <$fh>) { + if($line =~ m/^([^# \t]+).*\b\Q$host\E\b/) { + if($1 =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ && # IP-Address + $1<256 && $2<256 && $3<256 && $4<256) { + $fn->($hash, undef, pack("CCCC", $1, $2, $3, $4)); + close($fh); + return; + } + } + } + close($fh); + } + } + # Direct DNS Query via UDP my $c = IO::Socket::INET->new(Proto=>'udp', PeerAddr=>"$dnsServer:53"); return $fn->($hash, "Cant create UDP socket:$!", undef) if(!$c); diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html index b87a097f4..5b7559d1f 100644 --- a/fhem/docs/commandref_frame.html +++ b/fhem/docs/commandref_frame.html @@ -1428,6 +1428,13 @@ The following local attributes are used by a wider range of devices: dynamically.
+ +
  • dnsHostsFile
    + If dnsServer is set, check the contents of the file specified as + argument. To use the system hosts file, set it to /etc/hosts on + Linux/Unix/OSX and C:\windows\system32\drivers\etc\hosts on Windows. +

  • +
  • dnsServer
    Contains the IP address of the DNS Server. If some of the modules or diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html index 85e6eee8e..8042727fe 100644 --- a/fhem/docs/commandref_frame_DE.html +++ b/fhem/docs/commandref_frame_DE.html @@ -1520,6 +1520,14 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet: waehrend der Laufzeit per JavaScript geladen.

  • + +
  • dnsHostsFile
    + Falls dnsServer gesetzt ist, wird die angegebene Datei nach dem + Hostnamen durchsucht. Um die vom System verwendete Datei zu benutzen, + ist es unter Linux/Unix/OSX auf /etc/hosts und unter Windows auf + C:\windows\system32\drivers\etc\hosts zu setzen. +

  • +
  • dnsServer
    Enthält die IP Adresse des DNS Servers. Die von bestimmten Modulen diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 20558f799..6c23d8a17 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -290,6 +290,7 @@ my @globalAttrList = qw( blockingCallMax commandref:modular,full configfile + dnsHostsFile dnsServer dupTimeout exclude_from_update