🌐 öffentliche IP ermitteln, public IPv4 and IPv6

Begonnen von Torxgewinde, 13 Juni 2025, 16:49:15

Vorheriges Thema - Nächstes Thema

passibe

#15
Hi,
Zitat von: JoWiemann am 18 Juni 2025, 12:26:42das Ergebnis von
Code Auswählen Erweitern
get get <name> tr064Command WANPPPConnection:1 wanpppconn1 GetInfo
da kriege ich nur:
Service='WANPPPConnection:1'   Control='wanpppconn1'   Action='GetInfo'
----------------------------------------------------------------------
$VAR1 = {
          'UPnPError' => {
                           'errorCode' => '401',
                           'errorDescription' => 'Invalid Action'
                         }
        };

Hab mal mit den Werten aus dem cURL request rumprobiert, das hier funktioniert:
get <NAME> tr064Command WANIPConnection:1 wanipconnection1 GetExternalIPAddress

---
Service='WANIPConnection:1'   Control='wanipconnection1'   Action='GetExternalIPAddress'
----------------------------------------------------------------------
$VAR1 = {
          'GetExternalIPAddressResponse' => {
                                              'NewExternalIPAddress' => '2a02:xxxx:xxx::xxx'
                                            }
        };
Macht wohl auch Sinn, dass WANPPPConnection nichts ausgibt, sondern es WANIPConnection ist, weil ich mich bei DOCSIS eben nicht über PPPoE (wie bei DSL/FTTH) einlogge.
Vielleicht kannst du das ja dann für die Kabelboxen einbauen. Wenn ich mehr testen soll, sag gerne Bescheid!

Vielleicht noch ein paar mehr Infos, nachdem ich mal in der tr64desc.xml gelesen habe:
get <NAME> tr064Command WANIPConnection:1 wanipconnection1 GetInfo

---
Service='WANIPConnection:1'   Control='wanipconnection1'   Action='GetInfo'
----------------------------------------------------------------------
$VAR1 = {
          'GetInfoResponse' => {
                                 'NewConnectionType' => 'IP_Routed',
                                 'NewDNSOverrideAllowed' => '1',
                                 'NewEnable' => '1',
                                 'NewPossibleConnectionTypes' => 'IP_Routed, IP_Bridged',
                                 'NewConnectionTrigger' => 'OnDemand',
                                 'NewExternalIPAddress' => '2a02:xxxx:xxx::xxx',
                                 'NewMACAddress' => '48:5D:35:xx:xx:xx',
                                 'NewUptime' => '2457037',
                                 'NewDNSEnabled' => '1',
                                 'NewName' => 'internet',
                                 'NewLastConnectionError' => 'ERROR_NONE',
                                 'NewDNSServers' => '2a02:908:2:b::1, 2a02:908:2:a::1',
                                 'NewRSIPAvailable' => '0',
                                 'NewConnectionStatus' => 'Connected',
                                 'NewRouteProtocolRx' => 'Off',
                                 'NewNATEnabled' => '1'
                               }
        };

get <NAME> tr064Command WANCommonInterfaceConfig:1 wancommonifconfig1 GetCommonLinkProperties

---
Service='WANCommonInterfaceConfig:1'   Control='wancommonifconfig1'   Action='GetCommonLinkProperties'
----------------------------------------------------------------------
$VAR1 = {
          'GetCommonLinkPropertiesResponse' => {
                                                 'NewLayer1DownstreamMaxBitRate' => '273920000',
                                                 'NewX_AVM-DE_DownstreamCurrentMaxSpeed' => '31238',
                                                 'NewX_AVM-DE_UpstreamCurrentUtilization' => '3003,2802,3679,1786,5153,5343,2572,16984,3214,4109,9354,3979,2887,1560,874,12711,1626,3257,1840,3108',
                                                 'NewX_AVM-DE_DownstreamCurrentUtilization' => '5474,9271,8996,11246,2186,5182,19059,4730,31238,887,1629,7386,9381,3127,1344,29896,7989,4140,8864,3548',
                                                 'NewLayer1UpstreamMaxBitRate' => '52480000',
                                                 'NewWANAccessType' => 'X_AVM-DE_Cable',
                                                 'NewPhysicalLinkStatus' => 'Up',
                                                 'NewX_AVM-DE_UpstreamCurrentMaxSpeed' => '16984'
                                               }
        };

JoWiemann

Hallo passibe,

im FritzBox Modul prüfe ich für die Cable Boxen das Ergebnis von get get <name> tr064Command WANPPPConnection:1 wanpppconn1 GetInfo und ermittle dann die IPv4/6 über die TR064 Funktion WANIPConnection:1. Somit sollte box_ipv4 und box_ipv6 vorhanden sein.

Grüße Jörg
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

passibe

Hi, dann läuft bei mir wohl was schief.
Vielleicht hängt das damit zusammen, dass NewExternalIPAddress bei mir direkt schon eine IPv6 ist?
Wobei, ich habe mal mit verbose 5 getestet und sehe da nur 500er:

2025.06.18 14:05:11 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6551] - EXPANDED:uptimeConnect- start getting TR064 data
2025.06.18 14:05:11 4:[box | 6660 | 252.07.58 | SOAP_Request.12580] - EXPANDED:SOAP response error: 500 Internal Server Error
2025.06.18 14:05:11 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6555] - EXPANDED:SOAP-ERROR -> SOAP response error: 500 Internal Server Error
2025.06.18 14:05:11 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6586] - EXPANDED:uptimeConnect- end getting TR064 data
2025.06.18 14:05:11 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6591] - EXPANDED:ipExtern- start getting TR064 data
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | SOAP_Request.12580] - EXPANDED:SOAP response error: 500 Internal Server Error
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6597] - EXPANDED:SOAP-ERROR -> SOAP response error: 500 Internal Server Error
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6610] - EXPANDED:ipExtern- end getting TR064 data
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6618] - EXPANDED:ipv6 - start getting TR064 data
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | SOAP_Request.12580] - EXPANDED:SOAP response error: 500 Internal Server Error
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6625] - EXPANDED:SOAP/TR064-ERROR -> SOAP response error: 500 Internal Server Error
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Add_Reading.7228] - EXPANDED:box_ipv6_Extern:
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6638] - EXPANDED:ipv6 - end getting TR064 data
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6643] - EXPANDED:ipv6_Prefix - start getting TR064 data
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | SOAP_Request.12580] - EXPANDED:SOAP response error: 500 Internal Server Error
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6650] - EXPANDED:SOAP/TR064-ERROR -> SOAP response error: 500 Internal Server Error
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Add_Reading.7228] - EXPANDED:box_ipv6_Extern:
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6663] - EXPANDED:ipv6_Prefix - start getting TR064 data
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6667] - EXPANDED:AccessType - start getting TR064 data
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | SOAP_Request.12580] - EXPANDED:SOAP response error: 500 Internal Server Error
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6674] - EXPANDED:SOAP/TR064-ERROR -> SOAP response error: 500 Internal Server Error
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Add_Reading.7228] - EXPANDED:box_wan_AccessType:
2025.06.18 14:05:12 4:[box | 6660 | 252.07.58 | Readout_Run_Web_TR064.6693] - EXPANDED:AccessType - end getting TR064 data
Irgendwie scheint da also der SOAP Aufruf nicht zu passen?
get <NAME> tr064Command WANIPConnection:1 wanipconnection1 GetInfo funktioniert aber nach wie vor.

JoWiemann

Hallo passibe,

vielen Dank für die Rückmeldung. Ist aber ein Fehler im Code oder eine Änderung von AVM, die ich nicht mitbekommen habe. Muss ich mir jetzt mal genauer ansehen.

Ich würde das Thema dann ab jetzt im passenden Bereich für das FritzBox Modul weiter bearbeiten. https://forum.fhem.de/index.php?msg=1343435

Grüße Jörg
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

Torxgewinde

#19
Zitat von: Gisbert am 18 Juni 2025, 11:51:40in der Kommandoteile bekomme ich kein Ergebnis zurück. Das notwendige Perl-Paket ist installiert. Im Logfile sehe ich keine Hinweise, die darauf hindeuten könnten, dass etwas in Schieflage ist.

Den Code kann man auch so ausprobieren:
define at_number at +*00:10 {\
  use Net::Address::IP::Local;;\
  my $address   = eval {Net::Address::IP::Local->public};;\
  $data{myip}   = $address unless ($@);;\
  $address      = eval {Net::Address::IP::Local->public_ipv4};;\
  $data{myipv4} = $address unless ($@);;\
  $address      = eval { Net::Address::IP::Local->public_ipv6};;\
  $data{myipv6} = $address unless ($@);;\
  \
  my $hash = $defs{$SELF};;\
  readingsBeginUpdate($hash);;\
  readingsBulkUpdate($hash, "IP", $data{myip});;\
  readingsBulkUpdate($hash, "IPv4", $data{myipv4});;\
  readingsBulkUpdate($hash, "IPv6", $data{myipv6});;\
  readingsEndUpdate($hash, 1);;\
}

Testweise/Temporär auch bei Cooltux: https://demo-fhem.cooltux.net/fhem?detail=at_number&fw_id=#

Der Snippet von @betateilchen ermittelt allerdings maximal eine IPv4 und maximal eine IPv6 Adresse. Sollte dein FHEM mehrere Adressen haben tauchen diese nicht auf (Doku dazu: https://metacpan.org/pod/Net::Address::IP::Local, falls das Perl Modul nicht installiert ist dann sudo apt install libnet-address-ip-local-perl). Der Snippet der im Kern das Programm "ip" nutzt kann mehrere IPs auflisten.