New config (Ignore download times: yes/no)
[enigma2-plugins.git] / rsdownloader / src / FritzReconnect.py
1 import socket
2
3 def reconnect(host='fritz.box', port=49000):
4         http_body = '\r\n'.join((
5                 '<?xml version="1.0" encoding="utf-8"?>',
6                 '<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">',
7                 '  <s:Body>',
8                 '    <u:ForceTermination xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"/>',
9                 '  </s:Body>',
10                 '</s:Envelope>'))
11         http_data = '\r\n'.join((
12                 'POST /upnp/control/WANIPConn1 HTTP/1.1',
13                 'Host: %s:%d' % (host, port),
14                 'SoapAction: urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination',
15                 'Content-Type: text/xml; charset="utf-8"',
16                 'Content-Length: %d' % len(http_body),
17                 '',
18                 http_body))
19         
20         try:
21                 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
22                 s.connect((host, port))
23                 s.send(http_data)
24                 s.close()
25                 return True
26         except:
27                 return False
28