From 5859b2cd4b480d82783a5ed6c894ffa4ea3d057e Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Wed, 18 Oct 2017 19:46:13 +0000
Subject: [PATCH] HttpUtils.pm: add global dnsHostsFile attribute
git-svn-id: https://svn.fhem.de/fhem/trunk@15284 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/HttpUtils.pm | 18 ++++++++++++++++++
fhem/docs/commandref_frame.html | 7 +++++++
fhem/docs/commandref_frame_DE.html | 8 ++++++++
fhem/fhem.pl | 1 +
5 files changed, 35 insertions(+)
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.
+
+