Autor Beitrag
sensei
Hält's aus hier
Beiträge: 5


Delphi 2009
BeitragVerfasst: Mi 08.04.09 10:32 
Hallo,
um meine FRITZ!Box abzumelden und mir anschließend eine neue IP-Adresse zu beschaffen verwende ich folgendes Script im Zusammenhang mit curl:

curl "http://fritz.box:49000/upnp/control/WANIPConn1" -H "Content-Type: text/xml; charset="utf-8"" -H "SoapAction:urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination" -d "<?xml version='1.0' encoding='utf-8'?> <s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'> <s:Body> <u:ForceTermination xmlns:u='urn:schemas-upnp-org:service:WANIPConnection:1' /> </s:Body> </s:Envelope>"

Dies funktioniert auch wunderbar, allerdings würde ich das gerne in ein eigenes Programm integrieren ohne curl zu verwenden.
Ich habe es mit IdHTTP versucht, aber habe es nicht hinbekommen.
Hat jemand eine Idee wie es funktionieren könnte?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 08.04.09 10:46 
UPnP nutzt UDP für eine Reihe von Dingen. Zudem sollte es reichen, ein entsprechendes Datenpaket (sihe HTTP-Spezifikation) aufzubereiten und zu senden.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
sensei Threadstarter
Hält's aus hier
Beiträge: 5


Delphi 2009
BeitragVerfasst: Mi 08.04.09 10:56 
Wie würde der entsprechende Quellcode aussehen um das UDP Paket zu senden?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 08.04.09 11:02 
Minimal könnte es so gehen:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
GET /upnp/control/WANIPConn1 HTTP/1.1
Host: fritz.box
Content-Type: text/xml; charset="utf-8"
Content-Length: Länge des Contents hier eintragen in Bytes
SoapAction:urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination

<?xml version='1.0' encoding='utf-8'?>
<s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>
<s:Body>
<u:ForceTermination xmlns:u='urn:schemas-upnp-org:service:WANIPConnection:1' />
</s:Body>
</s:Envelope>


Bei einem mit IdUDP über Port 49000 gesendeten Paket
(Fehler vorbehalten)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
sensei Threadstarter
Hält's aus hier
Beiträge: 5


Delphi 2009
BeitragVerfasst: Mi 08.04.09 11:35 
Ich habe jetzt folgende Prozedur geschrieben, allerdings ohne Erfolg:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure FBdisconnect;
var
  sock: TUDPSocket;
  buffer: String;
begin
  sock := TUDPSocket.Create(nil);
  sock.RemoteHost := 'fritz.box';
  sock.RemotePort := '49000';
  sock.Open;
  buffer := 'POST /upnp/control/WANIPConn1 HTTP/1.1'+#13+#10+
  'Host: fritz.box'+#13+#10+
  'Content-Type: text/xml; charset="utf-8"'+#13+#10+
  'Content-Length: 276'+#13+#10+
  'SoapAction:urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination'+#13+#10+
  '<?xml version=''1.0'' encoding=''utf-8''?> <s:Envelope s:encodingStyle=''http://schemas.xmlsoap.org/soap/encoding/'' xmlns:s=''http://schemas.xmlsoap.org/soap/envelope/''> '+
  '<s:Body> <u:ForceTermination xmlns:u=''urn:schemas-upnp-org:service:WANIPConnection:1'' /> </s:Body> </s:Envelope>';
  sock.SendBuf(buffer,length(buffer));
  sock.Close;
  sock.Free;
end;
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 08.04.09 11:53 
Die Leerzeile nach den Headern ist notwendig. Siehe RFC ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
sensei Threadstarter
Hält's aus hier
Beiträge: 5


Delphi 2009
BeitragVerfasst: Mi 08.04.09 12:00 
Die Leerzeile habe ich jetzt hinzugefügt.
Es funktioniert trotzdem nicht.
Ich hab mir das Paket mit Wireshark angeguckt.
Da ist zwischen jedem Zeichen des Strings ein #0.
Wie bekomme ich das weg?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 08.04.09 12:17 
Deklarier deinen String als AnsiString, sonst nutzt Delphi 2009 WideStrings.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
sensei Threadstarter
Hält's aus hier
Beiträge: 5


Delphi 2009
BeitragVerfasst: Mi 08.04.09 12:24 
Danke!

So funtioniert es:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
procedure FBdisconnect;
var
  sock: TTcpClient;
  buffer: AnsiString;
begin
  sock := TTcpClient.Create(nil);
  sock.RemoteHost := 'fritz.box';
  sock.RemotePort := '49000';
  sock.Open;

  buffer :=
  'POST /upnp/control/WANIPConn1 HTTP/1.1'+#13+#10+
  'Host: fritz.box:49000'+#13+#10+
  'Accept: */*'+#13+#10+
  'Content-Type: text/xml; charset=utf-8'+#13+#10+
  'SoapAction:urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination'+#13+#10+
  'Content-Length: 276'+#13+#10+
  ''+#13+#10+
  '<?xml version=''1.0'' encoding=''utf-8''?> <s:Envelope s:encodingStyle=''http://schemas.xmlsoap.org/soap/encoding/'' xmlns:s=''http://schemas.xmlsoap.org/soap/envelope/''> '+
  '<s:Body> <u:ForceTermination xmlns:u=''urn:schemas-upnp-org:service:WANIPConnection:1'' /> </s:Body> </s:Envelope>';

  sock.SendBuf(buffer[1],length(buffer));
  sock.Close;
  sock.Free;
end;


Ich habs jetzt aber als TCP geschickt, weil curl das auch macht.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 08.04.09 13:09 
Tipp am Rande: Du kannst auch einfach 'Hallo'#13#10#13#10'Welt!' schreiben, das ist auch gültig und liest sich oftmals besser, als die vielen + dazwischen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mi 08.04.09 13:19 
Das finde ich persönlich schlechter zu lesen. Ich mag am liebsten folgendes:
ausblenden Delphi-Quelltext
1:
2:
3:
'Hallo' + #13#10 +
#13#10 +
'Welt!'
(inkl. der Leerschritte zwischen den + und dem Zeilenumbruch).

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)