FritzConnection Eine Python-Schnittstelle zur AVM FritzBox 1
Detailinformationen von AVM: http://www.avm.de/de/news/artikel/schnittstellen_und_entwicklungen.php Per Navigation auf www.avm.de (für mich) unauffindbar. 2
FritzConnection FritzTools FritzStatus FritzMonitor https://bitbucket.org/kbr/fritzconnection fritzconnection: fritzstatus: fritzmonitor: Schnittstelle zur FritzBox FritzBox-Statusinformationen GUI-Aktivitätsmonitor (TkInter) 3
FritzBox liefert Schnittstellenbeschreibung via xml-dateien: igddesc.xml tr64desc.xml Zugriff per http: IP: 169.254.1.1 Port: 49000 4
TR-064: basierend auf UPnP (Universal Plug and Play) Informationen TR-064: http://www.broadband-forum.org/technical/download/tr-064.pdf http://www.avm.de/de/extern/files/tr-064/avm_technical_note_- _Konfiguration_ueber_TR-064.pdf http://www.avm.de/de/extern/files/tr-064/avm_tr-064_first_steps.pdf Informationen UPnP: http://upnp.org/ https://developer.gnome.org/gupnp/unstable/server-tutorial.html 5
igddesc.xml (Internet Gateway Device Description) <service> <servicetype>urn:schemas-upnp-org:service:wancommoninterfaceconfig:1</servicetype> <serviceid>urn:upnp-org:serviceid:wancommonifc1</serviceid> <controlurl>/upnp/control/wancommonifc1</controlurl> <eventsuburl>/upnp/control/wancommonifc1</eventsuburl> <SCPDURL>/igdicfgSCPD.xml</SCPDURL> </service> Service Control Protocol Document 6
igdicfgscpd.xml (Internet Gateway Device Internal Configuration Service Control Protocol Document) <action> <name>gettotalbytesreceived</name> <argumentlist> <argument> <name>newtotalbytesreceived</name> <direction>out</direction> <relatedstatevariable>totalbytesreceived</relatedstatevariable> </argument> </argumentlist> </action>... <statevariable sendevents="no"> <name>totalbytesreceived</name> <datatype>ui4</datatype> </statevariable> 7
FritzConnection: Anwendungsbeispiel if name == ' main ': print('fritzconnection:') fc = FritzConnection() print(fc.modelname) print(fc.actionnames) print(fc.get_action_arguments('getstatusinfo')) print(fc.call_action('getstatusinfo')) print(fc.call_action('gettotalbytessent')) print(fc.call_action('gettotalbytesreceived')) print(fc.call_action('getexternalipaddress')) print(fc.call_action('getcommonlinkproperties')) 8
Output: FritzConnection: FRITZ!Box Fon WLAN 7390 ['AddPortMapping', 'DeletePortMapping', 'ForceTermination', 'GetATMEncapsulation', 'GetAddonInfos', 'GetAutoConfig', 'GetCommonLinkProperties', 'GetConnectionTypeInfo', 'GetDSLLinkInfo', 'GetDestinationAddress', 'GetExternalIPAddress', 'GetFCSPreserved', 'GetGenericPortMappingEntry', 'GetModulationType', 'GetNATRSIPStatus', 'GetSpecificPortMappingEntry', 'GetStatusInfo', 'GetTotalBytesReceived', 'GetTotalBytesSent', 'GetTotalPacketsReceived', 'GetTotalPacketsSent', 'RequestConnection', 'SetATMEncapsulation', 'SetConnectionType', 'SetDSLLinkType', 'SetDestinationAddress', 'SetFCSPreserved'] [('NewUptime', 'out', 'ui4'), ('NewLastConnectionError', 'out', 'string'), ('NewConnectionStatus', 'out', 'string')] {'NewConnectionStatus': u'connected', 'NewLastConnectionError': u'error_none', 'NewUptime': 50301} {'NewTotalBytesSent': 181458037} {'NewTotalBytesReceived': 873834710} {'NewExternalIPAddress': u'93.223.160.68'} {'NewWANAccessType': u'dsl', 'NewLayer1DownstreamMaxBitRate': 51376000, 'NewPhysicalLinkStatus': u'up', 'NewLayer1UpstreamMaxBitRate': 10048000} 9
IO: if name == ' main ': print('fritzconnection:') fc = FritzConnection() -- print(fc.modelname) FritzConnection: FRITZ!Box Fon WLAN 7390 10
IO: if name == ' main ':... print(fc.actionnames) -- ['AddPortMapping', 'DeletePortMapping', 'ForceTermination', 'GetATMEncapsulation', 'GetAddonInfos', 'GetAutoConfig', 'GetCommonLinkProperties', 'GetConnectionTypeInfo', 'GetDSLLinkInfo', 'GetDestinationAddress', 'GetExternalIPAddress', 'GetFCSPreserved', 'GetGenericPortMappingEntry', 'GetModulationType', 'GetNATRSIPStatus', 'GetSpecificPortMappingEntry', 'GetStatusInfo', 'GetTotalBytesReceived', 'GetTotalBytesSent', 'GetTotalPacketsReceived', 'GetTotalPacketsSent', 'RequestConnection', 'SetATMEncapsulation', 'SetConnectionType', 'SetDSLLinkType', 'SetDestinationAddress', 'SetFCSPreserved'] 11
IO: if name == ' main ':... print(fc.get_action_arguments('getstatusinfo')) print(fc.call_action('getstatusinfo')) -- [('NewUptime', 'out', 'ui4'), ('NewLastConnectionError', 'out', 'string'), ('NewConnectionStatus', 'out', 'string')] {'NewConnectionStatus': u'connected', 'NewLastConnectionError': u'error_none', 'NewUptime': 50301} 12
IO: if name == ' main ':... print(fc.call_action('gettotalbytessent')) print(fc.call_action('gettotalbytesreceived')) print(fc.call_action('getexternalipaddress')) print(fc.call_action('getcommonlinkproperties')) -- {'NewTotalBytesSent': 181458037} {'NewTotalBytesReceived': 873834710} {'NewExternalIPAddress': u'93.223.160.68'} {'NewWANAccessType': u'dsl', 'NewLayer1DownstreamMaxBitRate': 51376000, 'NewPhysicalLinkStatus': u'up', 'NewLayer1UpstreamMaxBitRate': 10048000} 13
FritzStatus: class FritzStatus(object): """ Class for requsting status-informations: """ @property def modelname(self): return self.fc.modelname @property def is_linked(self): """Returns True if the FritzBox is physically linked to the provider.""" status = self.fc.call_action('getcommonlinkproperties') return status['newphysicallinkstatus'] == 'Up' @property def is_connected(self): """ Returns True if the FritzBox has established an internet-connection. """ status = self.fc.call_action('getstatusinfo') return status['newconnectionstatus'] == 'Connected' 14
FritzStatus: if name == ' main ': fs = FritzStatus() print(fs.modelname) print(fs.bytes_sent) print(fs.bytes_received) print(fs.is_linked) print(fs.is_connected) print(fs.external_ip) print(fs.uptime) print(fs.str_uptime) print(fs.max_bit_rate) print(fs.max_byte_rate) print(fs.str_max_bit_rate) FRITZ!Box Fon WLAN 7390 89822389 245330020 True True 93.223.161.238 73175 20:19:35 (10048000, 51376000) (1256000, 6422000) ('9.0 MBit/s', '48.0 MBit/s') 15
FritzMonitor: 16
https://bitbucket.org/kbr/fritzconnection http://www.bremer-media.de/extras/fritzconnection.html 17