[SOLVED] How to open UPnP port with synapse
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
Key-Real · 2023-06-13 09:39
Hi
I cant open a port with UPnP
my Server to listen:
the Server works if I do PortForwarding
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {$MODE
OBJFPC}{$H+}uses blcksock, sockets, Synautil, SysUtils, HTTPSend,
synaip, Process, synamisc, crt;var soket : TUDPBlockSocket;
begin soket:= TUDPBlockSocket.Create;
soket.bind('0.0.0.0', '4444'); readln; soket.Free;end.
my Code to open the port:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {$MODE
OBJFPC}{$H+}uses httpsend,sysutils,classes,synautil;var f :
text; post : string; s : string; http :
THTTPSend; Response : TStringList;begin assignfile(f,
'add.xml'); reset(f); post:= ''; repeat
readln(f, s); post:= post + s; until
eof(f); close(f); //writeln(post);
http:=THTTPSend.Create; http.Document.Clear;
WriteStrToStream(HTTP.Document, post);
http.MimeType:='text/xml; charset="UTF-8"';
http.Headers.Add('SOAPAction: "urn:schemas-upnp-
org:service:WANIPConnection:1#AddPortMapping"'); if not
http.HTTPMethod('POST',
'http://192.168.0.1/upnp/control/WANIPConnection0') then begin
end; writeln(http.ResultCode);
writeln(http.ResultString); Response:= TStringList.Create;
Response.LoadFromStream(HTTP.Document); s:=
Response.Text; writeln(s); http.Free;
Response.Free;end.
the add.xml:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
test
0
192.168.0.4
True
3333
UDP
4444
the controll.xml sniped from my router:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
urn:schemas-upnp-
org:service:WANIPConnection:1urn:upnp-org:ser
viceId:WANIPConn1/WANIPConnectionServiceSCPD.xml<
/SCPDURL>/upnp/control/WANIPConnection0/upnp/event/WANIPConnection0
I get this if I send the M-SEARCH to my router:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i HTTP/1.1
200 OKCACHE-CONTROL: max-age=1800DATE: Tue, 13 Jun 2023 09:35:31
GMTEXT:LOCATION: http://192.168.0.1:49153/IGDdevicedesc_brlan0.xmlOPT:
"http://schemas.upnp.org/upnp/1/0/"; ns=0101-NLS:
b8c5fa84-09cc-11ee-a2e9-9217cd6c62d8SERVER: Linux/4.9.135-Prod_19.3,
UPnP/1.0, Portable SDK for UPnP devices/1.6.22X-User-Agent:
redsonicST: upnp:rootdeviceUSN:
uuid:ebf5a0a0-1dd1-11b2-a90f-021018951e6c::upnp:rootdevice
I check the openPort with nmap
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i sudo nmap
-sU -v -p 3333 31.18.77.240
what do I did wrong?
----------------------------------------------------------------------
rvk · 2023-06-13 09:55
Quote from: Key-Real on June 13, 2023, 11:39:49 amwhat do I did wrong?
Well, you don't mention to us what the result of the POST to
WANIPConnection0 is.
Are you sure UPnP is enabled on your router?
And you don't need to check with nmap. Just check in the router itself
if the UPnP is done correctly (there should be a list for this).
And otherwise you can do a POST with #GetGenericPortMappingEntry to
get the ports.
(You can also check with the utility miniupnp to see if the redirect
is done correctly.)
PS. The xml is correct (assuming the internal IP is correct). With the
same code (changing the internal IP) the xml works for me.
----------------------------------------------------------------------
Key-Real · 2023-06-13 11:20
then i do:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i #!
/usr/bin/env pythonimport miniupnpc # create the objectu =
miniupnpc.UPnP()u.discoverdelay = 200; print('Discovering...
delay=%ums' % u.discoverdelay)ndevices = u.discover()print(ndevices,
'device(s) detected') # select an igdu.selectigd() print('local ip
address :', u.lanaddr)externalipaddress =
u.externalipaddress()print('external ip address :',
externalipaddress) try: u.addportmapping(4444, 'UDP',
u.lanaddr, 4444, 'test', '') except: print('Fail')
and after that I start my server it works.
I have a code to return a M-SEARCH message from Router:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {$MODE
OBJFPC}uses sockets, SysUtils; procedure
SocketError(s:string);begin writeln('Scket Error: ', s);
halt(1);end; const MS = 'M-SEARCH * HTTP/1.1' + #$0D + #$0A +
'HOST:239.255.255.250:1900' + #$0D + #$0A + 'ST:upnp:rootdevice' +
#$0D + #$0A + 'MX:2' + #$0D + #$0A + 'MAN:"ssdp:discover"' +
#$0D + #$0A + #$0D + #$0A; var socket : longint; addr
: sockaddr_in; slen : dword; buf : array [0..8192] of
char;begin socket:= fpsocket(AF_INET, SOCK_DGRAM,
IPPROTO_UDP); if socket = -1 then SocketError('Init Socket');
fillchar(addr, 0, sizeof(addr)); addr.sin_family:= AF_INET;
addr.sin_addr:= StrToNetAddr('239.255.255.250');
addr.sin_port:= htons(1900); slen:= sizeof(addr); if
fpsendto(socket, pchar(MS), sizeof(MS), 0, @addr, sizeof(addr)) = -1
then SocketError('send MS message'); if fprecvfrom(socket,
@buf, sizeof(buf), 0, @addr, @slen) = -1 then SocketError('Receive
message from Router'); writeln('router send me this ip and
address as response: ',NetAddrToStr(addr.sin_addr), ':',
addr.sin_port); writeln(buf); closeSocket(socket);end.
it returns:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i router send
me this ip and address as response: 192.168.0.1:63633HTTP/1.1 200
OKCACHE-CONTROL: max-age=1800DATE: Tue, 13 Jun 2023 11:06:18
GMTEXT:LOCATION: http://192.168.0.1:49153/IGDdevicedesc_brlan0.xmlOPT:
"http://schemas.upnp.org/upnp/1/0/"; ns=0101-NLS:
b8c5fa84-09cc-11ee-a2e9-9217cd6c62d8SERVER: Linux/4.9.135-Prod_19.3,
UPnP/1.0, Portable SDK for UPnP devices/1.6.22X-User-Agent:
redsonicST: upnp:rootdeviceUSN:
uuid:ebf5a0a0-1dd1-11b2-a90f-021018951e6c::upnp:rootdevice
so I do:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {$MODE
OBJFPC}{$H+}uses httpsend,sysutils,classes,synautil; var S, Found:
String; HTTP: THTTPSend; Location,ServiceType : String; Response :
TStringList; f:text;begin // SHOULD I ADD THE PORT NUMBER
QUTED IN THE root.xml ? // the port 63633 is returned router
address on the resoponse to the M-SEARCH // nothing happens
// The port: 49153 is retrunden in the M-SEARCH MESSAGE itself
// here i get 400 Bad Request // without the port I get a
long response, I post it Location :=
'http://192.168.0.1/upnp/control/WANIPConnection0'; ServiceType
:= 'urn:schemas-upnp-org:service:WANIPConnection:1'; S := ''; S :=
S + ''; S := S + ''; S := S
+ ' '; S := S + ' '; S := S +
' 0'; S := S + '
'; S := S + ' '; S := S +
''; Response := TStringList.Create; HTTP :=
THTTPSend.Create; try WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: ' + ServiceType +
'#GetGenericPortMappingEntry'); if HTTP.HTTPMethod('POST',
Location) then begin Response.LoadFromStream(HTTP.Document);
Found := Response.Text; writeln(found); end; finally
Response.Free; HTTP.Free;
end; assign(f,'res.html');rewrite(f);writeln(f,found);close(f);end.
the response I put in attachment
PS: Unfortunly my Router doesn't list the UPnP ports
PSS:
I posted a sniped of my conrtoll.xml (or root.xml).
It is retruned by
http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
----------------------------------------------------------------------
rvk · 2023-06-13 11:33
Yeah, that result is just html.
You are quering port 80.
You should include the found port in your location.
:49153
So
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Location :=
'http://192.168.0.1:49153/upnp/control/WANIPConnection0';
----------------------------------------------------------------------
Key-Real · 2023-06-13 11:35
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Location
:= 'http://192.168.0.1:49153/upnp/control/WANIPConnection0';
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
400 Bad Request
----------------------------------------------------------------------
rvk · 2023-06-13 11:58
Weird. Here my code from a few weeks ago (which lists the UPnP
redirects).
I used hardcode for Gateway but you could put in some code to check
for the correct one.
(So I didn't loop all results from M-SEARCH but directly send an
M-SEARCH to the known gateway)
Put the exact code in a program and run it. What is the output?
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
upnp; {$MODE OBJFPC}{$H+}uses Classes, blcksock, synautil,
SysUtils, RegExpr, httpsend; function GetStringBetweenAndStrip(var
str: string; startStr, endStr: string): string; var startPos,
endPos: integer; begin startStr := uppercase(startStr); endStr
:= uppercase(endStr); startPos := Pos(startStr, uppercase(str));
if startPos = 0 then exit(''); startPos := startPos +
Length(startStr); endPos := Pos(endStr, uppercase(str), startPos);
if endPos = 0 then exit(''); Result := Copy(str, startPos, endPos
- startPos); // strip the string startPos := startPos -
Length(startStr); endPos := endPos + Length(endStr);
System.Delete(str, startPos, endPos - startPos); end; var GatewayIP,
Location, Base, Found, Found1, Service, S: string; ServiceType:
string; Socket: TUDPBlockSocket; Response: TStringList; HTTP:
THTTPSend; ResultCode: integer; Idx: integer; eH, eP, Pr, iP, iH,
iE, iD, iL: string;begin GatewayIP := '192.168.0.1'; // I used
hardcoded Gateway here. You can also listen for any other upnp device
and pick that one. S := 'M-SEARCH * HTTP/1.1'#13#10 + 'HOST:
239.255.255.250:1900'#13#10 + 'MAN: "ssdp:discover"'#13#10 + 'MX:
3'#13#10 + 'ST: upnp:rootdevice'#13#10#13#10; Socket :=
TUDPBlockSocket.Create; Socket.EnableBroadcast(True);
Socket.Connect(GatewayIP, '1900'); Socket.SendString(S); repeat
if Socket.CanRead(3000) then begin Found :=
Socket.RecvPacket(3000); if Pos('LOCATION: ', uppercase(Found)) >
0 then begin Location := Copy(Found, Pos('LOCATION:',
uppercase(Found)) + 9); Location := Trim(Copy(Location, 1,
Pos(#13#10, Location) - 1)); writeln('Location is ' +
Location); Response := TStringList.Create; try
HttpGetText(Location, Response); Found := Response.Text;
Base := Location; // take base of Location for control
while (Base <> '') and (Location[Length(Base)] <> '/') do Delete(Base,
Length(Base), 1); if Base <> '' then Delete(Base,
Length(Base), 1); writeln('Base is ' + Base); //
loop all services repeat Service :=
GetStringBetweenAndStrip(Found, '', '');
if Pos(uppercase(':WANIPConnection:'), uppercase(service)) > 0 then
begin S := GetStringBetweenAndStrip(Service,
'', ''); if S <> '' then
begin Location := Base + S;
writeln('Control URL is ' + Location);
HttpGetText(Location, Response); S := Response.Text;
if Pos(uppercase('AddPortMapping'),
uppercase(S)) > 0 then begin
ServiceType := GetStringBetweenAndStrip(Service, '',
''); S :=
GetStringBetweenAndStrip(Service, '', '');
Location := Base + S; Idx := 0;
repeat S := ''; S :=
S + ''; S :=
S + '';
S := S + ' '; S := S + '
'; S := S + '
' + IntToStr(Idx) + '';
S := S + ' ';
S := S + ' '; S := S +
''; HTTP := THTTPSend.Create;
try WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: ' + ServiceType +
'#GetGenericPortMappingEntry'); if
HTTP.HTTPMethod('POST', Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document); Found :=
Response.Text; // writeln(found);
repeat Found1 :=
GetStringBetweenAndStrip(Found,
''); if
Found1 <> '' then begin
eH := GetStringBetweenAndStrip(Found1, '',
''); eP :=
GetStringBetweenAndStrip(Found1, '',
''); Pr :=
GetStringBetweenAndStrip(Found1, '', '');
iP := GetStringBetweenAndStrip(Found1,
'', '');
iH := GetStringBetweenAndStrip(Found1, '',
''); iE :=
GetStringBetweenAndStrip(Found1, '', '');
iD := GetStringBetweenAndStrip(Found1,
'', '');
iL := GetStringBetweenAndStrip(Found1,
'', '');
S := Format('%s %s:%s -> %s:%s En: %s De: %s Le: %s', [Pr, eH, eP,
iH, iP, iE, iD, iL]); writeln(S);
end; until Found1 = '';
end; finally HTTP.Free;
end; Inc(Idx); until
Resultcode <> 200; end; end;
end; until service = ''; finally
Response.Free; end; end; break; end;
sleep(100); until False; Socket.CloseSocket; Socket.Free;
writeln('we are done, press enter'); readln; end.
----------------------------------------------------------------------
Key-Real · 2023-06-13 12:02
I started the python script, than
I started the program as it is
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Location is
http://192.168.0.1:49153/IGDdevicedesc_brlan0.xmlBase is
http://192.168.0.1:49153Control URL is
http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xmlwe are done,
press enter
----------------------------------------------------------------------
rvk · 2023-06-13 12:09
That seems to be correct.
(I made an error. I printed the SCPDUrl as Control URL.)
It should be:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
upnp; {$MODE OBJFPC}{$H+}uses Classes, blcksock, synautil,
SysUtils, RegExpr, httpsend; function GetStringBetweenAndStrip(var
str: string; startStr, endStr: string): string; var startPos,
endPos: integer; begin startStr := uppercase(startStr); endStr
:= uppercase(endStr); startPos := Pos(startStr, uppercase(str));
if startPos = 0 then exit(''); startPos := startPos +
Length(startStr); endPos := Pos(endStr, uppercase(str), startPos);
if endPos = 0 then exit(''); Result := Copy(str, startPos, endPos
- startPos); // strip the string startPos := startPos -
Length(startStr); endPos := endPos + Length(endStr);
System.Delete(str, startPos, endPos - startPos); end; var GatewayIP,
Location, Base, Found, Found1, Service, S: string; ServiceType:
string; Socket: TUDPBlockSocket; Response: TStringList; HTTP:
THTTPSend; ResultCode: integer; Idx: integer; eH, eP, Pr, iP, iH,
iE, iD, iL: string;begin GatewayIP := '192.168.0.1'; // I used
hardcoded Gateway here. You can also listen for any other upnp device
and pick that one. S := 'M-SEARCH * HTTP/1.1'#13#10 + 'HOST:
239.255.255.250:1900'#13#10 + 'MAN: "ssdp:discover"'#13#10 + 'MX:
3'#13#10 + 'ST: upnp:rootdevice'#13#10#13#10; Socket :=
TUDPBlockSocket.Create; Socket.EnableBroadcast(True);
Socket.Connect(GatewayIP, '1900'); Socket.SendString(S); repeat
if Socket.CanRead(3000) then begin Found :=
Socket.RecvPacket(3000); if Pos('LOCATION: ', uppercase(Found)) >
0 then begin Location := Copy(Found, Pos('LOCATION:',
uppercase(Found)) + 9); Location := Trim(Copy(Location, 1,
Pos(#13#10, Location) - 1)); writeln('Location is ' +
Location); Response := TStringList.Create; try
HttpGetText(Location, Response); Found := Response.Text;
Base := Location; // take base of Location for control
while (Base <> '') and (Location[Length(Base)] <> '/') do Delete(Base,
Length(Base), 1); if Base <> '' then Delete(Base,
Length(Base), 1); writeln('Base is ' + Base); //
loop all services repeat Service :=
GetStringBetweenAndStrip(Found, '', '');
if Pos(uppercase(':WANIPConnection:'), uppercase(service)) > 0 then
begin S := GetStringBetweenAndStrip(Service,
'', ''); if S <> '' then
begin Location := Base + S;
writeln('SCPDURL is ' + Location);
HttpGetText(Location, Response); S := Response.Text;
if Pos(uppercase('AddPortMapping'),
uppercase(S)) > 0 then begin
ServiceType := GetStringBetweenAndStrip(Service, '',
''); S :=
GetStringBetweenAndStrip(Service, '', '');
Location := Base + S; writeln('Control
URL is ' + Location); Idx := 0;
repeat S := ''; S := S + ''; S := S +
'';
S := S + ' '; S := S + '
'; S := S + '
' + IntToStr(Idx) + '';
S := S + ' ';
S := S + ' '; S := S +
''; HTTP := THTTPSend.Create;
try WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: ' + ServiceType +
'#GetGenericPortMappingEntry'); if
HTTP.HTTPMethod('POST', Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document); Found :=
Response.Text; // writeln(found);
repeat Found1 :=
GetStringBetweenAndStrip(Found,
''); if
Found1 <> '' then begin
eH := GetStringBetweenAndStrip(Found1, '',
''); eP :=
GetStringBetweenAndStrip(Found1, '',
''); Pr :=
GetStringBetweenAndStrip(Found1, '', '');
iP := GetStringBetweenAndStrip(Found1,
'', '');
iH := GetStringBetweenAndStrip(Found1, '',
''); iE :=
GetStringBetweenAndStrip(Found1, '', '');
iD := GetStringBetweenAndStrip(Found1,
'', '');
iL := GetStringBetweenAndStrip(Found1,
'', '');
S := Format('%s %s:%s -> %s:%s En: %s De: %s Le: %s', [Pr, eH, eP,
iH, iP, iE, iD, iL]); writeln(S);
end; until Found1 = '';
end; finally HTTP.Free;
end; Inc(Idx); until
Resultcode <> 200; end; end;
end; until service = ''; finally
Response.Free; end; end; break; end;
sleep(100); until False; Socket.CloseSocket; Socket.Free;
writeln('we are done, press enter'); readln; end.
For me this results in (using 192.168.2.1 as my gateway of course):
Code: [Select]Location is http://192.168.2.1:60687/rootDesc.xml
Base is http://192.168.2.1:60687
SCPDURL is http://192.168.2.1:60687/WANIPCn.xml
Control URL is http://192.168.2.1:60687/ctl/IPConn
UDP :3333 -> 192.168.2.21:4444 En: De: test Le: 0
we are done, press enter
(I've already successfully inserted that port 4444 with your code.)
----------------------------------------------------------------------
Key-Real · 2023-06-13 12:12
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Location is
http://192.168.0.1:49153/IGDdevicedesc_brlan0.xmlBase is
http://192.168.0.1:49153SCPDURL is
http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xmlControl URL is
http://192.168.0.1:49153/upnp/control/WANIPConnection0we are done,
press enter
----------------------------------------------------------------------
rvk · 2023-06-13 12:18
Here is code for adding a port and querying it aftwerwards. (I used
port 3331 here for clarity)
Note: 192.168.0.4 needs to be an existing computer in the network.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
upnp; {$MODE OBJFPC}{$H+}uses Classes, blcksock, synautil,
SysUtils, RegExpr, httpsend; function GetStringBetweenAndStrip(var
str: string; startStr, endStr: string): string; var startPos,
endPos: integer; begin startStr := uppercase(startStr); endStr
:= uppercase(endStr); startPos := Pos(startStr, uppercase(str));
if startPos = 0 then exit(''); startPos := startPos +
Length(startStr); endPos := Pos(endStr, uppercase(str), startPos);
if endPos = 0 then exit(''); Result := Copy(str, startPos, endPos
- startPos); // strip the string startPos := startPos -
Length(startStr); endPos := endPos + Length(endStr);
System.Delete(str, startPos, endPos - startPos); end; var GatewayIP,
Location, Base, Found, Found1, Service, S: string; ServiceType:
string; Socket: TUDPBlockSocket; Response: TStringList; HTTP:
THTTPSend; ResultCode: integer; Idx: integer; eH, eP, Pr, iP, iH,
iE, iD, iL: string;begin GatewayIP := '192.168.0.1'; // I used
hardcoded Gateway here. You can also listen for any other upnp device
and pick that one. S := 'M-SEARCH * HTTP/1.1'#13#10 + 'HOST:
239.255.255.250:1900'#13#10 + 'MAN: "ssdp:discover"'#13#10 + 'MX:
3'#13#10 + 'ST: upnp:rootdevice'#13#10#13#10; Socket :=
TUDPBlockSocket.Create; Socket.EnableBroadcast(True);
Socket.Connect(GatewayIP, '1900'); Socket.SendString(S); repeat
if Socket.CanRead(3000) then begin Found :=
Socket.RecvPacket(3000); if Pos('LOCATION: ', uppercase(Found)) >
0 then begin Location := Copy(Found, Pos('LOCATION:',
uppercase(Found)) + 9); Location := Trim(Copy(Location, 1,
Pos(#13#10, Location) - 1)); writeln('Location is ' +
Location); Response := TStringList.Create; try
HttpGetText(Location, Response); Found := Response.Text;
Base := Location; // take base of Location for control
while (Base <> '') and (Location[Length(Base)] <> '/') do Delete(Base,
Length(Base), 1); if Base <> '' then Delete(Base,
Length(Base), 1); writeln('Base is ' + Base); //
loop all services repeat Service :=
GetStringBetweenAndStrip(Found, '', '');
if Pos(uppercase(':WANIPConnection:'), uppercase(service)) > 0 then
begin S := GetStringBetweenAndStrip(Service,
'', ''); if S <> '' then
begin Location := Base + S;
writeln('SCPDURL is ' + Location);
HttpGetText(Location, Response); S := Response.Text;
if Pos(uppercase('AddPortMapping'),
uppercase(S)) > 0 then begin
ServiceType := GetStringBetweenAndStrip(Service, '',
''); S :=
GetStringBetweenAndStrip(Service, '', '');
Location := Base + S; writeln('Control
URL is ' + Location); // HERE WE INSERT
s := ''; s := s + '';
s := s + ''; s := s + '
'; s := s + '
test';
s := s + ' 0';
s := s + '
192.168.0.4';
s := s + ' True'; s
:= s + ' 3331';
s := s + ' ';
s := s + ' UDP';
s := s + ' 4444';
s := s + ' '; s := s +
''; s := s + ''; HTTP := THTTPSend.Create;
try WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
http.Headers.Add('SOAPAction: "urn:schemas-upnp-
org:service:WANIPConnection:1#AddPortMapping"');
if HTTP.HTTPMethod('POST', Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document); Found :=
Response.Text; writeln(found);
end; finally HTTP.Free;
end; // HERE WE CHECK Idx
:= 0; repeat S := '';
S := S + '';
S := S + '';
S := S + ' '; S := S + '
'; S := S + '
' + IntToStr(Idx) + '';
S := S + ' ';
S := S + ' '; S := S +
''; HTTP := THTTPSend.Create;
try WriteStrToStream(HTTP.Document,
S); HTTP.MimeType := 'text/xml;
charset="utf-8"'; HTTP.Headers.Add('SOAPAction: '
+ ServiceType + '#GetGenericPortMappingEntry');
if HTTP.HTTPMethod('POST', Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document);
Found := Response.Text; // writeln(found);
repeat Found1 :=
GetStringBetweenAndStrip(Found,
'');
if Found1 <> '' then begin
eH := GetStringBetweenAndStrip(Found1, '',
''); eP :=
GetStringBetweenAndStrip(Found1, '',
''); Pr :=
GetStringBetweenAndStrip(Found1, '', '');
iP := GetStringBetweenAndStrip(Found1,
'', '');
iH := GetStringBetweenAndStrip(Found1, '',
''); iE :=
GetStringBetweenAndStrip(Found1, '', '');
iD := GetStringBetweenAndStrip(Found1,
'', '');
iL := GetStringBetweenAndStrip(Found1,
'', '');
S := Format('%s %s:%s -> %s:%s En: %s De: %s Le: %s', [Pr, eH, eP,
iH, iP, iE, iD, iL]); writeln(S);
end; until Found1 = '';
end; finally
HTTP.Free; end; Inc(Idx);
until Resultcode <> 200; end;
end; end; until service = ''; finally
Response.Free; end; end; break; end;
sleep(100); until False; Socket.CloseSocket; Socket.Free;
writeln('we are done, press enter'); readln; end.
----------------------------------------------------------------------
rvk · 2023-06-13 12:21
I hardcoded the http.Headers.Add('SOAPAction: in my previous example.
That should be the exact ServiceType as the xml descibed (see the
GetGenericPortMappingEntry code).
But for now they are the same so the example should work.
----------------------------------------------------------------------
Key-Real · 2023-06-13 12:21
QuoteLocation is http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49153
SCPDURL is http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49153/upnp/control/WANIPConnection0
s:Client
UPnPError
402
PAL_UPNP_SOAP_E_INVALID_ARGS
----------------------------------------------------------------------
rvk · 2023-06-13 12:23
Ah, progress
Quote from: Key-Real on June 13, 2023, 02:21:56
pms:Client
Is that 192.168.0.4 a valid computer?
----------------------------------------------------------------------
Key-Real · 2023-06-13 12:24
Quote[key-real@koshka upnp]$ ip address
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp7s0: mtu 1500 qdisc mq state
UP group default qlen 1000
link/ether d8:bb:c1:a2:2b:35 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.4/24 metric 100 brd 192.168.0.255 scope global
dynamic enp7s0
valid_lft 586912sec preferred_lft 586912sec
inet6 fe80::dabb:c1ff:fea2:2b35/64 scope link
valid_lft forever preferred_lft forever
3: wlo1: mtu 1500 qdisc noqueue
state DOWN group default qlen 1000
link/ether 60:dd:8e:a5:2f:a8 brd ff:ff:ff:ff:ff:ff
altname wlp0s20f3
----------------------------------------------------------------------
rvk · 2023-06-13 12:38
Is the miniupnpc utility able to insert a portforward?
Or does that also give an error?
http://miniupnp.free.fr/
Code: [Select]/usr/bin/upnpc -r 3332 UDP
----------------------------------------------------------------------
Key-Real · 2023-06-13 12:41
Quote[key-real@koshka upnp]$ upnpc -r 3332 UDP
upnpc : miniupnpc library test client, version 2.2.4.
(c) 2005-2022 Thomas Bernard.
Go to http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
for more information.
List of UPNP devices found on the network :
desc: http://192.168.0.1:49155/IGDdevicedesc_brlan0.xml
st: urn:schemas-upnp-org:device:InternetGatewayDevice:1
Found valid IGD :
http://192.168.0.1:49155/upnp/control/WANIPConnection0
Local LAN ip address : 192.168.0.4
ExternalIPAddress = 31.18.77.240
InternalIP:Port = 192.168.0.4:3332
external 31.18.77.240:3332 UDP is redirected to internal
192.168.0.4:3332 (duration=0)
----------------------------------------------------------------------
rvk · 2023-06-13 12:51
So it should work.
That one sees port 49155.
Error 402 is
Parameters are missing, extra, or are invalid for this action. See the
description of Control in [UPNPARCH1.1] section 3.
If you have tcpdump you could do a tcpdump on one terminal and execute
that upnpc command on another.
This will list all traffic outgoing on destination port 49155. Change
it to the same port as the latest command.
Code: Bash [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i sudo
tcpdump -n dst port 49155
I catch this:
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Host:
192.168.2.1:43493User-Agent: Debian/bullseye/sid, UPnP/1.1,
MiniUPnPc/2.2.1Content-Length: 596Content-Type: text/xmlSOAPAction:
"urn:schemas-upnp-
org:service:WANIPConnection:1#AddPortMapping"Connection: CloseCache-
Control: no-cachePragma: no-cache 33364UDP33364192.168.2.211libminiupnpc0
(pretty xml)
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
33364
UDP
33364
192.168.2.21
1
libminiupnpc
0
Order of arguments could be important.
----------------------------------------------------------------------
Key-Real · 2023-06-13 12:55
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i [key-
real@koshka upnp]$ sudo tcpdump -n dst port 49155tcpdump: verbose
output suppressed, use -v[v]... for full protocol decodelistening on
enp7s0, link-type EN10MB (Ethernet), snapshot length 262144
bytes14:54:09.934291 IP 192.168.0.4.46338 > 192.168.0.1.49155: Flags
[S], seq 1933787470, win 64240, options [mss 1460,sackOK,TS val
622119008 ecr 0,nop,wscale 7], length 014:54:09.935723 IP
192.168.0.4.46338 > 192.168.0.1.49155: Flags [.], ack 1769740677, win
502, options [nop,nop,TS val 622119009 ecr 145991940], length
014:54:09.935835 IP 192.168.0.4.46338 > 192.168.0.1.49155: Flags [P.],
seq 0:139, ack 1, win 502, options [nop,nop,TS val 622119009 ecr
145991940], length 13914:54:09.937388 IP 192.168.0.4.46338 >
192.168.0.1.49155: Flags [.], ack 273, win 500, options [nop,nop,TS
val 622119011 ecr 145991941], length 014:54:09.937454 IP
192.168.0.4.46338 > 192.168.0.1.49155: Flags [.], ack 1721, win 499,
options [nop,nop,TS val 622119011 ecr 145991942], length
014:54:09.937496 IP 192.168.0.4.46338 > 192.168.0.1.49155: Flags [.],
ack 3169, win 499, options [nop,nop,TS val 622119011 ecr 145991942],
length 014:54:09.937550 IP 192.168.0.4.46338 > 192.168.0.1.49155:
Flags [F.], seq 139, ack 3298, win 501, options [nop,nop,TS val
622119011 ecr 145991942], length 014:54:09.937590 IP 192.168.0.4.46342
> 192.168.0.1.49155: Flags [S], seq 3418843113, win 64240, options
[mss 1460,sackOK,TS val 622119011 ecr 0,nop,wscale 7], length
014:54:09.938823 IP 192.168.0.4.46342 > 192.168.0.1.49155: Flags [.],
ack 2029789123, win 502, options [nop,nop,TS val 622119012 ecr
145991943], length 014:54:09.938845 IP 192.168.0.4.46342 >
192.168.0.1.49155: Flags [P.], seq 0:580, ack 1, win 502, options
[nop,nop,TS val 622119012 ecr 145991943], length 58014:54:09.940798 IP
192.168.0.4.46342 > 192.168.0.1.49155: Flags [.], ack 230, win 501,
options [nop,nop,TS val 622119014 ecr 145991945], length
014:54:09.940853 IP 192.168.0.4.46342 > 192.168.0.1.49155: Flags [F.],
seq 580, ack 640, win 501, options [nop,nop,TS val 622119014 ecr
145991945], length 014:54:09.940870 IP 192.168.0.4.46350 >
192.168.0.1.49155: Flags [S], seq 1096853470, win 64240, options [mss
1460,sackOK,TS val 622119014 ecr 0,nop,wscale 7], length
014:54:09.942167 IP 192.168.0.4.46350 > 192.168.0.1.49155: Flags [.],
ack 137316309, win 502, options [nop,nop,TS val 622119015 ecr
145991946], length 014:54:09.942183 IP 192.168.0.4.46350 >
192.168.0.1.49155: Flags [P.], seq 0:601, ack 1, win 502, options
[nop,nop,TS val 622119015 ecr 145991946], length 60114:54:09.944014 IP
192.168.0.4.46350 > 192.168.0.1.49155: Flags [.], ack 230, win 501,
options [nop,nop,TS val 622119017 ecr 145991948], length
014:54:09.944119 IP 192.168.0.4.46350 > 192.168.0.1.49155: Flags [F.],
seq 601, ack 572, win 501, options [nop,nop,TS val 622119017 ecr
145991948], length 014:54:09.944132 IP 192.168.0.4.46360 >
192.168.0.1.49155: Flags [S], seq 3406302317, win 64240, options [mss
1460,sackOK,TS val 622119017 ecr 0,nop,wscale 7], length
014:54:09.945429 IP 192.168.0.4.46360 > 192.168.0.1.49155: Flags [.],
ack 3279800914, win 502, options [nop,nop,TS val 622119019 ecr
145991950], length 014:54:09.945440 IP 192.168.0.4.46360 >
192.168.0.1.49155: Flags [P.], seq 0:601, ack 1, win 502, options
[nop,nop,TS val 622119019 ecr 145991950], length 60114:54:09.947547 IP
192.168.0.4.46360 > 192.168.0.1.49155: Flags [.], ack 230, win 501,
options [nop,nop,TS val 622119021 ecr 145991952], length
014:54:09.947635 IP 192.168.0.4.46360 > 192.168.0.1.49155: Flags [F.],
seq 601, ack 572, win 501, options [nop,nop,TS val 622119021 ecr
145991952], length 014:54:09.947644 IP 192.168.0.4.46366 >
192.168.0.1.49155: Flags [S], seq 1371474331, win 64240, options [mss
1460,sackOK,TS val 622119021 ecr 0,nop,wscale 7], length
014:54:09.949030 IP 192.168.0.4.46366 > 192.168.0.1.49155: Flags [.],
ack 2584397854, win 502, options [nop,nop,TS val 622119022 ecr
145991953], length 014:54:09.949046 IP 192.168.0.4.46366 >
192.168.0.1.49155: Flags [P.], seq 0:905, ack 1, win 502, options
[nop,nop,TS val 622119022 ecr 145991953], length 90514:54:10.065977 IP
192.168.0.4.46366 > 192.168.0.1.49155: Flags [.], ack 230, win 501,
options [nop,nop,TS val 622119139 ecr 145992070], length
014:54:10.066094 IP 192.168.0.4.46366 > 192.168.0.1.49155: Flags [F.],
seq 905, ack 499, win 501, options [nop,nop,TS val 622119139 ecr
145992070], length 014:54:10.066187 IP 192.168.0.4.46376 >
192.168.0.1.49155: Flags [S], seq 1038112737, win 64240, options [mss
1460,sackOK,TS val 622119139 ecr 0,nop,wscale 7], length
014:54:10.067396 IP 192.168.0.4.46376 > 192.168.0.1.49155: Flags [.],
ack 1781443229, win 502, options [nop,nop,TS val 622119141 ecr
145992071], length 014:54:10.067492 IP 192.168.0.4.46376 >
192.168.0.1.49155: Flags [P.], seq 0:723, ack 1, win 502, options
[nop,nop,TS val 622119141 ecr 145992071], length 72314:54:10.070661 IP
192.168.0.4.46376 > 192.168.0.1.49155: Flags [.], ack 230, win 501,
options [nop,nop,TS val 622119144 ecr 145992074], length
014:54:10.070754 IP 192.168.0.4.46376 > 192.168.0.1.49155: Flags [F.],
seq 723, ack 758, win 501, options [nop,nop,TS val 622119144 ecr
145992075], length 0
----------------------------------------------------------------------
rvk · 2023-06-13 12:57
O sorry, I forgot the -A in that tcpdump command.
It will print out the XML.
BTW. Try this in my code:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
s := ''; s := s + '';
s := s + ''; s := s + '
'; s := s + '
'; s := s + '
3331'; s := s + '
UDP'; s := s + '
4444'; s := s
+ ' 192.168.0.4';
s := s + ' 1';
s := s + '
test';
s := s + ' 0';
s := s + ' '; s
:= s + ''; s := s + '';
Different argument order (and 1 instead of True).
----------------------------------------------------------------------
Key-Real · 2023-06-13 13:02
QuoteLocation is http://192.168.0.1:49155/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49155
SCPDURL is http://192.168.0.1:49155/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49155/upnp/control/WANIPConnection0
we are done, press enter
----------------------------------------------------------------------
rvk · 2023-06-13 13:03
Quote from: Key-Real on June 13, 2023, 03:02:01 pmQuoteLocation is
http://192.168.0.1:49155/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49155
SCPDURL is http://192.168.0.1:49155/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49155/upnp/control/WANIPConnection0
we are done, press enter
I think that's a 200 response (I didn't print that out but looking at
the xml, the port should now be forwarded.
But if you used my code... it should query the ports afterwards and
that result seems empty
What does upnpc -l say?
----------------------------------------------------------------------
Key-Real · 2023-06-13 13:06
Quote[key-real@koshka upnp]$ upnpc -r 49166 UDP
upnpc : miniupnpc library test client, version 2.2.4.
(c) 2005-2022 Thomas Bernard.
Go to http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
for more information.
List of UPNP devices found on the network :
desc: http://192.168.0.1:49155/IGDdevicedesc_brlan0.xml
st: urn:schemas-upnp-org:device:InternetGatewayDevice:1
Found valid IGD :
http://192.168.0.1:49155/upnp/control/WANIPConnection0
Local LAN ip address : 192.168.0.4
ExternalIPAddress = 31.18.77.240
InternalIP:Port = 192.168.0.4:49166
external 31.18.77.240:49166 UDP is redirected to internal
192.168.0.4:49166 (duration=0)
[key-real@koshka upnp]$ upnpc -l
upnpc : miniupnpc library test client, version 2.2.4.
(c) 2005-2022 Thomas Bernard.
Go to http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
for more information.
List of UPNP devices found on the network :
desc: http://192.168.0.1:49155/IGDdevicedesc_brlan0.xml
st: urn:schemas-upnp-org:device:InternetGatewayDevice:1
Found valid IGD :
http://192.168.0.1:49155/upnp/control/WANIPConnection0
Local LAN ip address : 192.168.0.4
Connection Type : IP_Routed
Status : Connected, uptime=0s, LastConnectionError : ERROR_NONE
MaxBitRateDown : 100000000 bps (100.0 Mbps) MaxBitRateUp 100000000
bps (100.0 Mbps)
ExternalIPAddress = 31.18.77.240
i protocol exPort->inAddr:inPort description remoteHost leaseTime
GetGenericPortMappingEntry() returned 713 (SpecifiedArrayIndexInvalid)
----------------------------------------------------------------------
rvk · 2023-06-13 13:19
Quote from: Key-Real on June 13, 2023, 03:06:38 pm[key-real@koshka
upnp]$ upnpc -l
[...]
i protocol exPort->inAddr:inPort description remoteHost leaseTime
GetGenericPortMappingEntry() returned 713 (SpecifiedArrayIndexInvalid)
So upnpc doesn't give an error when setting a port forward.
But it doesn't show any forwarded ports.
Weird.
You can put this around line 150 of my example:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
Response.LoadFromStream(HTTP.Document);
Found := Response.Text;
writeln(HTTP.ResultCode.ToString + ' ' + found); just to see what the
resultcode is.
But if you (and miniupnp) doesn't get an error but still doesn't add
the forward, I wonder if something else is broken.
----------------------------------------------------------------------
Key-Real · 2023-06-13 13:21
QuoteLocation is http://192.168.0.1:49155/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49155
SCPDURL is http://192.168.0.1:49155/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49155/upnp/control/WANIPConnection0
400 400 Bad Request
we are done, press enter
----------------------------------------------------------------------
Key-Real · 2023-06-13 13:28
A snipet from
http://192.168.0.1:49155/WANIPConnectionServiceSCPD.xml
Quote
GetGenericPortMappingEntry
NewPortMappingIndex
in
PortMappingNumberOfEntries
NewRemoteHost
out
RemoteHost
NewExternalPort
out
ExternalPort
NewProtocol
out
PortMappingProtocol
NewInternalPort
out
InternalPort
NewInternalClient
out
InternalClient
NewEnabled
out
PortMappingEnabled
NewPortMappingDescription
out
PortMappingDescription
NewLeaseDuration
out
PortMappingLeaseDuration
----------------------------------------------------------------------
rvk · 2023-06-13 13:32
New code with all the Resultcode:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
upnp; {$MODE OBJFPC}{$H+}uses Classes, blcksock, synautil,
SysUtils, RegExpr, httpsend; function GetStringBetweenAndStrip(var
str: string; startStr, endStr: string): string; var startPos,
endPos: integer; begin startStr := uppercase(startStr); endStr
:= uppercase(endStr); startPos := Pos(startStr, uppercase(str));
if startPos = 0 then exit(''); startPos := startPos +
Length(startStr); endPos := Pos(endStr, uppercase(str), startPos);
if endPos = 0 then exit(''); Result := Copy(str, startPos, endPos
- startPos); // strip the string startPos := startPos -
Length(startStr); endPos := endPos + Length(endStr);
System.Delete(str, startPos, endPos - startPos); end; var GatewayIP,
Location, Base, Found, Found1, Service, S: string; ServiceType:
string; Socket: TUDPBlockSocket; Response: TStringList; HTTP:
THTTPSend; ResultCode: integer; Idx: integer; eH, eP, Pr, iP, iH,
iE, iD, iL: string;begin GatewayIP := '192.168.0.1'; // I used
hardcoded Gateway here. You can also listen for any other upnp device
and pick that one. S := 'M-SEARCH * HTTP/1.1'#13#10 + 'HOST:
239.255.255.250:1900'#13#10 + 'MAN: "ssdp:discover"'#13#10 + 'MX:
3'#13#10 + 'ST: upnp:rootdevice'#13#10#13#10; Socket :=
TUDPBlockSocket.Create; Socket.EnableBroadcast(True);
Socket.Connect(GatewayIP, '1900'); Socket.SendString(S); repeat
if Socket.CanRead(3000) then begin Found :=
Socket.RecvPacket(3000); if Pos('LOCATION: ', uppercase(Found)) >
0 then begin Location := Copy(Found, Pos('LOCATION:',
uppercase(Found)) + 9); Location := Trim(Copy(Location, 1,
Pos(#13#10, Location) - 1)); writeln('Location is ' +
Location); Response := TStringList.Create; try
HttpGetText(Location, Response); Found := Response.Text;
Base := Location; // take base of Location for control
while (Base <> '') and (Location[Length(Base)] <> '/') do Delete(Base,
Length(Base), 1); if Base <> '' then Delete(Base,
Length(Base), 1); writeln('Base is ' + Base); //
loop all services repeat Service :=
GetStringBetweenAndStrip(Found, '', '');
if Pos(uppercase(':WANIPConnection:'), uppercase(service)) > 0 then
begin S := GetStringBetweenAndStrip(Service,
'', ''); if S <> '' then
begin Location := Base + S;
writeln('SCPDURL is ' + Location);
HttpGetText(Location, Response); S := Response.Text;
if Pos(uppercase('AddPortMapping'),
uppercase(S)) > 0 then begin
ServiceType := GetStringBetweenAndStrip(Service, '',
''); S :=
GetStringBetweenAndStrip(Service, '', '');
Location := Base + S; writeln('Control
URL is ' + Location); // HERE WE INSERT
s := ''; s := s + '';
s := s + ''; s := s + '
'; s
:= s + ' '; s
:= s + ' 3334';
s := s + ' UDP';
s := s + ' 4444';
s := s + '
192.168.0.4';
s := s + ' 1'; s := s
+ '
test';
s := s + ' 0';
s := s + ' '; s
:= s + ''; s := s + ''; HTTP := THTTPSend.Create;
try WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: ' + ServiceType +
'#AddPortMapping'); if HTTP.HTTPMethod('POST',
Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document); Found :=
Response.Text; writeln('');
writeln('Result of AddPort: ' + HTTP.ResultCode.ToString + ' ' +
found); end; finally
HTTP.Free; end; // HERE WE
CHECK Idx := 0; repeat
S := ''; S := S + '';
S := S + '';
S := S + ' '; S := S + '
';
S := S + ' ' + Idx.ToString +
''; S := S + '
'; S := S + '
'; S := S + '';
HTTP := THTTPSend.Create; try
WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: ' + ServiceType +
'#GetGenericPortMappingEntry'); if
HTTP.HTTPMethod('POST', Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document); Found
:= Response.Text; writeln('');
writeln('Result of GetPortMapping #' + Idx.ToString + ': ' +
HTTP.ResultCode.ToString + ' ' + found);
repeat Found1 :=
GetStringBetweenAndStrip(Found,
'');
if Found1 <> '' then begin
eH := GetStringBetweenAndStrip(Found1, '',
''); eP :=
GetStringBetweenAndStrip(Found1, '',
''); Pr :=
GetStringBetweenAndStrip(Found1, '', '');
iP := GetStringBetweenAndStrip(Found1,
'', '');
iH := GetStringBetweenAndStrip(Found1, '',
''); iE :=
GetStringBetweenAndStrip(Found1, '', '');
iD := GetStringBetweenAndStrip(Found1,
'', '');
iL := GetStringBetweenAndStrip(Found1,
'', '');
S := Format('%s %s:%s -> %s:%s En: %s De: %s Le: %s', [Pr, eH, eP,
iH, iP, iE, iD, iL]); writeln(S);
end; until Found1 = '';
end; finally
HTTP.Free; end; Inc(Idx);
until Resultcode <> 200; end;
end; end; until service = ''; finally
Response.Free; end; end; break; end;
sleep(100); until False; Socket.CloseSocket; Socket.Free;
writeln('we are done, press enter'); readln; end.
upnpc also just loops all the NewPortMappingIndex. But an error 400
should happen if on the same URL the AddPortMap is successful.
----------------------------------------------------------------------
Key-Real · 2023-06-13 13:37
QuoteLocation is http://192.168.0.1:49155/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49155
SCPDURL is http://192.168.0.1:49155/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49155/upnp/control/WANIPConnection0
Result of AddPort: 400 400 Bad
Request
Result of GetPortMapping #0: 400 400 Bad
Request
we are done, press enter
----------------------------------------------------------------------
rvk · 2023-06-13 13:43
Quote from: Key-Real on June 13, 2023, 03:37:21 pmQuoteLocation is
http://192.168.0.1:49155/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49155
SCPDURL is http://192.168.0.1:49155/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49155/upnp/control/WANIPConnection0
Result of AddPort: 400 400 Bad
Request
Result of GetPortMapping #0: 400 400 Bad
Request
we are done, press enter
If I look at your post here https://forum.lazarus.freepascal.org/index
.php/topic,63652.msg482505.html#msg482505
you got a valid response to the AddPort there.
(you couldn't get a Bad Request if you have valid xml there.
So something has changed
----------------------------------------------------------------------
rvk · 2023-06-13 13:47
Quote from: rvk on June 13, 2023, 03:43:29 pmSo something has changed
Is the ServiceType correctly extracted??
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
writeln('Control URL is ' + Location);
writeln('ServiceType is ' + ServiceType);
----------------------------------------------------------------------
Key-Real · 2023-06-13 13:50
Quote
Location is http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49153
SCPDURL is http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49153/upnp/control/WANIPConnection0
ServiceType is urn:schemas-upnp-org:service:WANIPConnection:1
Result of AddPort: 400 400 Bad
Request
Result of GetPortMapping #0: 400 400 Bad
Request
we are done, press enter
----------------------------------------------------------------------
rvk · 2023-06-13 13:57
That look correct. (you do see the port changing each time but that
shouldn't be a problem, it's the port the router provides.)
I don't know what we did different from 15:02:01 where the AddPort was
done correctly.
(you could try to go back to that version)
But still... if even upnpc can't pick a whole in the router, I wonder
if there is something else that's wrong.
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:04
Your Post at:
« Reply #9 on: Today at 02:18:33 pm »
gives:
QuoteLocation is http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49153
SCPDURL is http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49153/upnp/control/WANIPConnection0
s:Client
UPnPError
402
PAL_UPNP_SOAP_E_INVALID_ARGS
we are done, press enter
PS. I restored the code
----------------------------------------------------------------------
rvk · 2023-06-13 14:06
Quote from: Key-Real on June 13, 2023, 04:04:35 pmYour Post at:
« Reply #9 on: Today at 02:18:33 pm »
Yes, but your post from 15:02 has a valid xml response from the router
for AddPort.
Quote from: Key-Real on June 13, 2023, 03:02:01 pmQuoteLocation is
http://192.168.0.1:49155/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49155
SCPDURL is http://192.168.0.1:49155/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49155/upnp/control/WANIPConnection0
we are done, press enter
How did you manage that?
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:11
You mean this:
QuoteLocation is http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49153
SCPDURL is http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49153/upnp/control/WANIPConnection0
we are done, press enter
it's:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
upnp; {$MODE OBJFPC}{$H+} uses Classes,
blcksock, synautil, SysUtils, RegExpr, httpsend;
function GetStringBetweenAndStrip(var str: string; startStr,
endStr: string): string; var startPos, endPos: integer;
begin startStr := uppercase(startStr); endStr :=
uppercase(endStr); startPos := Pos(startStr, uppercase(str));
if startPos = 0 then exit(''); startPos := startPos +
Length(startStr); endPos := Pos(endStr, uppercase(str),
startPos); if endPos = 0 then exit(''); Result :=
Copy(str, startPos, endPos - startPos); // strip the string
startPos := startPos - Length(startStr); endPos := endPos +
Length(endStr); System.Delete(str, startPos, endPos -
startPos); end; var GatewayIP, Location, Base,
Found, Found1, Service, S: string; ServiceType: string;
Socket: TUDPBlockSocket; Response: TStringList; HTTP:
THTTPSend; ResultCode: integer; Idx: integer; eH, eP,
Pr, iP, iH, iE, iD, iL: string; begin GatewayIP :=
'192.168.0.1'; // I used hardcoded Gateway here. You can also listen
for any other upnp device and pick that one. S := 'M-SEARCH
* HTTP/1.1'#13#10 + 'HOST: 239.255.255.250:1900'#13#10 + 'MAN:
"ssdp:discover"'#13#10 + 'MX: 3'#13#10 + 'ST:
upnp:rootdevice'#13#10#13#10; Socket := TUDPBlockSocket.Create;
Socket.EnableBroadcast(True); Socket.Connect(GatewayIP,
'1900'); Socket.SendString(S); repeat if
Socket.CanRead(3000) then begin Found :=
Socket.RecvPacket(3000); if Pos('LOCATION: ',
uppercase(Found)) > 0 then begin Location :=
Copy(Found, Pos('LOCATION:', uppercase(Found)) + 9);
Location := Trim(Copy(Location, 1, Pos(#13#10, Location) - 1));
writeln('Location is ' + Location); Response :=
TStringList.Create; try
HttpGetText(Location, Response); Found := Response.Text;
Base := Location; // take base of Location for
control while (Base <> '') and (Location[Length(Base)] <>
'/') do Delete(Base, Length(Base), 1); if Base <> '' then
Delete(Base, Length(Base), 1); writeln('Base is ' +
Base); // loop all services repeat
Service := GetStringBetweenAndStrip(Found, '',
''); if Pos(uppercase(':WANIPConnection:'),
uppercase(service)) > 0 then begin S
:= GetStringBetweenAndStrip(Service, '', '');
if S <> '' then begin
Location := Base + S; writeln('SCPDURL is ' +
Location); HttpGetText(Location, Response);
S := Response.Text; if
Pos(uppercase('AddPortMapping'), uppercase(S)) > 0 then
begin ServiceType :=
GetStringBetweenAndStrip(Service, '', '');
S := GetStringBetweenAndStrip(Service,
'', ''); Location :=
Base + S; writeln('Control URL is ' + Location);
// HERE WE INSERT s
:= ''; s := s + '';
s := s + ''; s := s + '
'; s := s + '
'; s := s + '
3331'; s := s + '
UDP'; s := s + '
4444'; s := s
+ ' 192.168.0.4';
s := s + ' 1';
s := s + '
test';
s := s + ' 0';
s := s + ' '; s
:= s + ''; s := s + ''; HTTP := THTTPSend.Create;
try
WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
http.Headers.Add('SOAPAction: "urn:schemas-upnp-
org:service:WANIPConnection:1#AddPortMapping"');
if HTTP.HTTPMethod('POST', Location) then
begin Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document);
Found := Response.Text;
writeln(found); end;
finally HTTP.Free; end;
// HERE WE CHECK
Idx := 0; repeat S :=
''; S := S + ''; S := S + '';
S := S + ' '; S := S + '
'; S := S + '
' + IntToStr(Idx) + '';
S := S + ' ';
S := S + ' '; S := S
+ ''; HTTP :=
THTTPSend.Create; try
WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: ' + ServiceType +
'#GetGenericPortMappingEntry'); if
HTTP.HTTPMethod('POST', Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document);
Found := Response.Text; //
writeln(found); repeat
Found1 := GetStringBetweenAndStrip(Found,
'');
if Found1 <> '' then begin
eH := GetStringBetweenAndStrip(Found1,
'', '');
eP := GetStringBetweenAndStrip(Found1, '',
''); Pr :=
GetStringBetweenAndStrip(Found1, '', '');
iP := GetStringBetweenAndStrip(Found1,
'', '');
iH := GetStringBetweenAndStrip(Found1, '',
''); iE :=
GetStringBetweenAndStrip(Found1, '', '');
iD := GetStringBetweenAndStrip(Found1,
'', '');
iL := GetStringBetweenAndStrip(Found1,
'', '');
S := Format('%s %s:%s -> %s:%s En: %s De: %s Le: %s', [Pr, eH,
eP, iH, iP, iE, iD, iL]); writeln(S);
end; until
Found1 = ''; end;
finally HTTP.Free;
end; Inc(Idx); until
Resultcode <> 200; end;
end; end; until service = '';
finally Response.Free; end;
end; break; end; sleep(100); until
False; Socket.CloseSocket; Socket.Free; writeln('we are
done, press enter'); readln; end.
----------------------------------------------------------------------
rvk · 2023-06-13 14:15
Quote from: Key-Real on June 13, 2023, 04:11:53 pmYou mean this:
[..]
it's:
And that still gives the correct xml ??
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:16
I restored that code and executed it.
Is the response what You expected?
----------------------------------------------------------------------
rvk · 2023-06-13 14:17
Quote from: Key-Real on June 13, 2023, 04:16:51 pmI restored that code
and executed it.
Is the response what You expected?
If the response is this then yes. that's correct.
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
----------------------------------------------------------------------
rvk · 2023-06-13 14:20
Then you can add the following line at both the AddPort and
GetPortMapping code:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Found :=
Response.Text;writeln(HTTP.ResultCode.ToString + ' ' + found);
But the problem is the same as with upnpc.
It adds the port correctly but it doesn't list anything.
So there is a 'silent' error.
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:23
QuoteLocation is http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49153
SCPDURL is http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49153/upnp/control/WANIPConnection0
200
we are done, press enter
I started the the prog, and started server but the port still looks
closed, as nmap says
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:25
OW wait it is opened!!!!!!!!
----------------------------------------------------------------------
rvk · 2023-06-13 14:27
Then maybe just the GetGenericPortMappingEntry is defective in your
router.
(because upnpc also doesn't seem to get the listing correctly)
So AddPort seems to work.
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:28
I'm trying to get the pattern of starting your prog, the server and
nmap....
It looks randomly sequence...
mom......
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:30
I posted
« Reply #24 on: Today at 03:28:28 pm »
what about it?
is there a entry for quering?
----------------------------------------------------------------------
rvk · 2023-06-13 14:32
Quote from: Key-Real on June 13, 2023, 04:30:17 pmI posted
« Reply #24 on: Today at 03:28:28 pm »
what about it?
is there a entry for quering?
Yes. #GetGenericPortMappingEntry.
If you do a tcpdump with -A when doing the upnpc -l you get the
correct command and xml to post.
But that's also in my code.
And when you do upnpc -l you didn't get anything.
So I wonder is the #GetGenericPortMappingEntry isn't faulty in the
router.
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:34
The sequence seems to be:
1. start the server on port 4444
2. start the prog
3. start nmap
why i have to start the server first?
----------------------------------------------------------------------
rvk · 2023-06-13 14:36
Quote from: Key-Real on June 13, 2023, 04:34:28 pmwhy i have to start
the server first?
It shouldn't. The IP needs to be present in the network for the
AddPort to succeed.
But the port doesn't have to be open.
So this should also be possible.
1. start the prog to addport
2. start the server on port 4444
3. start nmap
----------------------------------------------------------------------
rvk · 2023-06-13 14:37
BTW, Can you do a writeln(s) before doing the
WriteStrToStream(HTTP.Document, S); for AddPort ?
(in the code you have now)
I find it really strange you get a 400 with my latest code:
(I added everything as constant parameters at the top)
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
upnp; {$MODE OBJFPC}{$H+}uses Classes, blcksock, synautil,
SysUtils, RegExpr, httpsend; const GatewayIP = '192.168.0.1'; // I
used hardcoded Gateway here. You can also listen for any other upnp
device and pick that one. IPIn = '192.168.0.4'; PortIn = '4444';
PortEx = '3341'; Debug = false; function
GetStringBetweenAndStrip(var str: string; startStr, endStr: string):
string; var startPos, endPos: integer; begin startStr :=
uppercase(startStr); endStr := uppercase(endStr); startPos :=
Pos(startStr, uppercase(str)); if startPos = 0 then exit('');
startPos := startPos + Length(startStr); endPos := Pos(endStr,
uppercase(str), startPos); if endPos = 0 then exit(''); Result
:= Copy(str, startPos, endPos - startPos); // strip the string
startPos := startPos - Length(startStr); endPos := endPos +
Length(endStr); System.Delete(str, startPos, endPos - startPos);
end; var Location, Base, Found, Found1, Service, S: string;
ServiceType: string; Socket: TUDPBlockSocket; Response:
TStringList; HTTP: THTTPSend; ResultCode: integer; Idx: integer;
eH, eP, Pr, iP, iH, iE, iD, iL: string;begin S := 'M-SEARCH *
HTTP/1.1'#13#10 + 'HOST: 239.255.255.250:1900'#13#10 + 'MAN:
"ssdp:discover"'#13#10 + 'MX: 3'#13#10 + 'ST:
upnp:rootdevice'#13#10#13#10; Socket := TUDPBlockSocket.Create;
Socket.EnableBroadcast(True); Socket.Connect(GatewayIP, '1900');
Socket.SendString(S); repeat if Socket.CanRead(3000) then
begin Found := Socket.RecvPacket(3000); if Pos('LOCATION: ',
uppercase(Found)) > 0 then begin Location := Copy(Found,
Pos('LOCATION:', uppercase(Found)) + 9); Location :=
Trim(Copy(Location, 1, Pos(#13#10, Location) - 1));
writeln('Location is ' + Location); Response :=
TStringList.Create; try HttpGetText(Location,
Response); Found := Response.Text; Base :=
Location; // take base of Location for control while (Base <>
'') and (Location[Length(Base)] <> '/') do Delete(Base, Length(Base),
1); if Base <> '' then Delete(Base, Length(Base), 1);
writeln('Base is ' + Base); // loop all services
repeat Service := GetStringBetweenAndStrip(Found,
'', ''); if
Pos(uppercase(':WANIPConnection:'), uppercase(service)) > 0 then
begin S := GetStringBetweenAndStrip(Service,
'', ''); if S <> '' then
begin Location := Base + S;
writeln('SCPDURL is ' + Location);
HttpGetText(Location, Response); S := Response.Text;
if Pos(uppercase('AddPortMapping'),
uppercase(S)) > 0 then begin
ServiceType := GetStringBetweenAndStrip(Service, '',
''); S :=
GetStringBetweenAndStrip(Service, '', '');
Location := Base + S; writeln('Control
URL is ' + Location); writeln('ServiceType is ' +
ServiceType); // HERE WE INSERT s
:= ''; s := s + '';
s := s + ''; s := s + '
'; s
:= s + ' '; s
:= s + ' ' + PortEx + '';
s := s + ' UDP';
s := s + ' ' + PortIn +
''; s := s + '
' + IPIn + '';
s := s + ' 1'; s :=
s + '
test';
s := s + ' 0';
s := s + ' '; s
:= s + ''; s := s + ''; HTTP := THTTPSend.Create;
try writeln;
writeln('posting ' + s); writeln;
WriteStrToStream(HTTP.Document, S); HTTP.MimeType
:= 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: ' + ServiceType + '#AddPortMapping');
if HTTP.HTTPMethod('POST', Location) then
begin Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document);
Found := Response.Text; if (HTTP.ResultCode
= 200) then writeln('Success adding port forward');
if (HTTP.ResultCode <> 200) or Debug then
begin writeln('');
writeln('Result of AddPort: ' + HTTP.ResultCode.ToString + ' ' +
found); end; end;
finally HTTP.Free; end;
// HERE WE CHECK Idx := 0;
repeat S := ''; S := S +
''; S := S + '';
S := S + ' '; S := S + '
';
S := S + ' ' + Idx.ToString +
''; S := S + '
'; S := S + '
'; S := S + '';
HTTP := THTTPSend.Create; try
WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: ' + ServiceType +
'#GetGenericPortMappingEntry'); if
HTTP.HTTPMethod('POST', Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document); Found
:= Response.Text; if Debug or ((HTTP.ResultCode
<> 200) and (HTTP.ResultCode <> 500)) then
begin writeln('');
writeln('Result of GetPortMapping #' + Idx.ToString + ': ' +
HTTP.ResultCode.ToString + ' ' + found); end;
repeat Found1 :=
GetStringBetweenAndStrip(Found,
'');
if Found1 <> '' then begin
eH := GetStringBetweenAndStrip(Found1, '',
''); eP :=
GetStringBetweenAndStrip(Found1, '',
''); Pr :=
GetStringBetweenAndStrip(Found1, '', '');
iP := GetStringBetweenAndStrip(Found1,
'', '');
iH := GetStringBetweenAndStrip(Found1, '',
''); iE :=
GetStringBetweenAndStrip(Found1, '', '');
iD := GetStringBetweenAndStrip(Found1,
'', '');
iL := GetStringBetweenAndStrip(Found1,
'', '');
S := Format('%s %s:%s -> %s:%s En: %s De: %s Le: %s', [Pr, eH, eP,
iH, iP, iE, iD, iL]); writeln(S);
end; until Found1 = '';
end; finally
HTTP.Free; end; Inc(Idx);
until Resultcode <> 200; end;
end; end; until service = ''; finally
Response.Free; end; end; break; end;
sleep(100); until False; Socket.CloseSocket; Socket.Free;
writeln('we are done, press enter'); readln; end.
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:39
QuoteLocation is http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49153
SCPDURL is http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49153/upnp/control/WANIPConnection0
ServiceType is urn:schemas-upnp-org:service:WANIPConnection:1
posting
3341
UDP
4444
192.168.0.4
1
test
0
Result of AddPort: 400 400 Bad
Request
Result of GetPortMapping #0: 400 400 Bad
Request
we are done, press enter
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:40
and he closes the port after some time (seems to be random, but i
don't knew)
----------------------------------------------------------------------
rvk · 2023-06-13 14:41
Quote from: Key-Real on June 13, 2023, 04:39:37 pmQuote...
And can you put the writeln(s) in your working code so we can compare
the xml which is posted.
Quote from: Key-Real on June 13, 2023, 04:40:39 pmand he closes the
port after some time (seems to be random, but i don't knew)
The lease time for open port can be extended.
(you now have 0 I thought)
0 could be a default of 3600 seconds.
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:45
You mean:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
writeln('ServiceType is ' + ServiceType);
I thought 0 in
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
0is forever?
----------------------------------------------------------------------
rvk · 2023-06-13 14:49
Quote from: Key-Real on June 13, 2023, 04:45:03 pmYou mean:Could you
put the line
writeln('posting ' + s);
above WriteStrToStream(HTTP.Document, S); in the AddPort section? (of
your now working code)
We need to compare the difference between my last code and your
working code.
Quote from: Key-Real on June 13, 2023, 04:45:03 pmI thought 0 in
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
0is forever?
Yes, 0 should be permanent.
But maybe not all routers follow this 'suggestion'.
If you see the UPnP disappear after some time, try to figure out what
that time is.
(but thats hard to do if you can't do a upnpc -l to check and the
GetPortMapping doesn't work)
----------------------------------------------------------------------
Key-Real · 2023-06-13 14:52
QuoteLocation is http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49153
SCPDURL is http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49153/upnp/control/WANIPConnection0
ServiceType is urn:schemas-upnp-org:service:WANIPConnection:1
posting
3331
UDP
4444
192.168.0.4
1
test
0
200
----------------------------------------------------------------------
rvk · 2023-06-13 14:57
Quote from: Key-Real on June 13, 2023, 04:52:28 pmQuote[...]Thanks...
Really weird... If I look at my own last code:
Quoteposting
3341
UDP
4444
192.168.0.4
1
test
0
Result of AddPort: 400 400 Bad
Request
Your working code:
Quoteposting
3331
UDP
4444
192.168.0.4
1
test
0
200
The xml seems to be exactly the same.
Only other difference is this for you:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
HTTP.MimeType := 'text/xml; charset="utf-8"';
http.Headers.Add('SOAPAction: "urn:schemas-upnp-
org:service:WANIPConnection:1#AddPortMapping"');and this for me:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: ' + ServiceType +
'#AddPortMapping');and your ServiceType variable stated:
Quoteurn:schemas-upnp-org:service:WANIPConnection:1
Maybe I'm blind but I can't spot the difference.
----------------------------------------------------------------------
rvk · 2023-06-13 15:00
Mmmm, only difference is the double quotes around the servicetype.
Can you try this version?
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
upnp; {$MODE OBJFPC}{$H+}uses Classes, blcksock, synautil,
SysUtils, RegExpr, httpsend; const GatewayIP = '192.168.0.1'; // I
used hardcoded Gateway here. You can also listen for any other upnp
device and pick that one. IPIn = '192.168.0.4'; PortIn = '4444';
PortEx = '3344'; Debug = false; function
GetStringBetweenAndStrip(var str: string; startStr, endStr: string):
string; var startPos, endPos: integer; begin startStr :=
uppercase(startStr); endStr := uppercase(endStr); startPos :=
Pos(startStr, uppercase(str)); if startPos = 0 then exit('');
startPos := startPos + Length(startStr); endPos := Pos(endStr,
uppercase(str), startPos); if endPos = 0 then exit(''); Result
:= Copy(str, startPos, endPos - startPos); // strip the string
startPos := startPos - Length(startStr); endPos := endPos +
Length(endStr); System.Delete(str, startPos, endPos - startPos);
end; var Location, Base, Found, Found1, Service, S: string;
ServiceType: string; Socket: TUDPBlockSocket; Response:
TStringList; HTTP: THTTPSend; ResultCode: integer; Idx: integer;
eH, eP, Pr, iP, iH, iE, iD, iL: string;begin S := 'M-SEARCH *
HTTP/1.1'#13#10 + 'HOST: 239.255.255.250:1900'#13#10 + 'MAN:
"ssdp:discover"'#13#10 + 'MX: 3'#13#10 + 'ST:
upnp:rootdevice'#13#10#13#10; Socket := TUDPBlockSocket.Create;
Socket.EnableBroadcast(True); Socket.Connect(GatewayIP, '1900');
Socket.SendString(S); repeat if Socket.CanRead(3000) then
begin Found := Socket.RecvPacket(3000); if Pos('LOCATION: ',
uppercase(Found)) > 0 then begin Location := Copy(Found,
Pos('LOCATION:', uppercase(Found)) + 9); Location :=
Trim(Copy(Location, 1, Pos(#13#10, Location) - 1));
writeln('Location is ' + Location); Response :=
TStringList.Create; try HttpGetText(Location,
Response); Found := Response.Text; Base :=
Location; // take base of Location for control while (Base <>
'') and (Location[Length(Base)] <> '/') do Delete(Base, Length(Base),
1); if Base <> '' then Delete(Base, Length(Base), 1);
writeln('Base is ' + Base); // loop all services
repeat Service := GetStringBetweenAndStrip(Found,
'', ''); if
Pos(uppercase(':WANIPConnection:'), uppercase(service)) > 0 then
begin S := GetStringBetweenAndStrip(Service,
'', ''); if S <> '' then
begin Location := Base + S;
writeln('SCPDURL is ' + Location);
HttpGetText(Location, Response); S := Response.Text;
if Pos(uppercase('AddPortMapping'),
uppercase(S)) > 0 then begin
ServiceType := GetStringBetweenAndStrip(Service, '',
''); S :=
GetStringBetweenAndStrip(Service, '', '');
Location := Base + S; writeln('Control
URL is ' + Location); writeln('ServiceType is ' +
ServiceType); // HERE WE INSERT s
:= ''; s := s + '';
s := s + ''; s := s + '
'; s
:= s + ' '; s
:= s + ' ' + PortEx + '';
s := s + ' UDP';
s := s + ' ' + PortIn +
''; s := s + '
' + IPIn + '';
s := s + ' 1'; s :=
s + '
test';
s := s + ' 0';
s := s + ' '; s
:= s + ''; s := s + ''; HTTP := THTTPSend.Create;
try WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: "' + ServiceType +
'#AddPortMapping"'); if HTTP.HTTPMethod('POST',
Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document); Found :=
Response.Text; if (HTTP.ResultCode = 200) then
writeln('Success adding port forward'); if
(HTTP.ResultCode <> 200) or Debug then begin
writeln(''); writeln('Result
of AddPort: ' + HTTP.ResultCode.ToString + ' ' + found);
end; end; finally
HTTP.Free; end; // HERE
WE CHECK writeln('Checking ports');
Idx := 0; repeat S := '';
S := S + ''; S := S
+ '';
S := S + ' '; S := S + '
';
S := S + ' ' + Idx.ToString +
''; S := S + '
'; S := S + '
'; S := S + '';
HTTP := THTTPSend.Create; try
WriteStrToStream(HTTP.Document, S);
HTTP.MimeType := 'text/xml; charset="utf-8"';
HTTP.Headers.Add('SOAPAction: "' + ServiceType +
'#GetGenericPortMappingEntry"'); if
HTTP.HTTPMethod('POST', Location) then begin
Resultcode := HTTP.ResultCode;
Response.LoadFromStream(HTTP.Document); Found
:= Response.Text; if Debug or ((HTTP.ResultCode
<> 200) and (HTTP.ResultCode <> 500)) then
begin writeln('');
writeln('Result of GetPortMapping #' + Idx.ToString + ': ' +
HTTP.ResultCode.ToString + ' ' + found); end;
repeat Found1 :=
GetStringBetweenAndStrip(Found,
'');
if Found1 <> '' then begin
eH := GetStringBetweenAndStrip(Found1, '',
''); eP :=
GetStringBetweenAndStrip(Found1, '',
''); Pr :=
GetStringBetweenAndStrip(Found1, '', '');
iP := GetStringBetweenAndStrip(Found1,
'', '');
iH := GetStringBetweenAndStrip(Found1, '',
''); iE :=
GetStringBetweenAndStrip(Found1, '', '');
iD := GetStringBetweenAndStrip(Found1,
'', '');
iL := GetStringBetweenAndStrip(Found1,
'', '');
S := Format('%s %s:%s -> %s:%s En: %s De: %s Le: %s', [Pr, eH, eP,
iH, iP, iE, iD, iL]); writeln(S);
end; until Found1 = '';
end; finally
HTTP.Free; end; Inc(Idx);
until Resultcode <> 200; end;
end; end; until service = ''; finally
Response.Free; end; end; break; end;
sleep(100); until False; Socket.CloseSocket; Socket.Free;
writeln('we are done, press enter'); readln; end.
----------------------------------------------------------------------
Key-Real · 2023-06-13 16:22
Great Success!!!!!!!
QuoteLocation is http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
Base is http://192.168.0.1:49153
SCPDURL is http://192.168.0.1:49153/WANIPConnectionServiceSCPD.xml
Control URL is http://192.168.0.1:49153/upnp/control/WANIPConnection0
ServiceType is urn:schemas-upnp-org:service:WANIPConnection:1
Success adding port forward
Checking ports
UDP :3344 -> 192.168.0.4:4444 En: De: test Le: 0
we are done, press enter
----------------------------------------------------------------------
rvk · 2023-06-13 16:24
Quote from: Key-Real on June 13, 2023, 06:22:11 pmGreat Success!!!!!!!
Yeah great
This was with my last code with the double quote around the
servicetype in the SOAP header?
(What a small character change can do )
----------------------------------------------------------------------
Key-Real · 2023-06-13 16:28
Big thx very much
I'm glad you could help
I'll have to go now, I'll try to close the port this week,
If You have an Idea about closing and about connection duration, pls
post
----------------------------------------------------------------------
rvk · 2023-06-13 18:01
Here is a small unit with a class to open and close the port.
(I don't know why 0 as lease doesn't work for you. Try to determine
the time-out when it gets deleted automatically)
This is example code to use the unit.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
upnptest; {$mode objfpc}{$H+} uses upnplibrary; var UPnP:
TUPnP;begin UPnP := TUPnP.Create('192.168.0.1'); if
UPnP.IsUPnPAvailable then begin Writeln('UPnP is available.');
Writeln('External IP: ', UPnP.ExternalIP); // Set a port mapping
if UPnP.SetPortMapping('192.168.0.4', 8081, 8000) = 200 then
begin writeln('Forward result is OK'); writeln('Check port.
Press Enter to delete and terminate'); readln; end else
begin writeln('Error forwarding '); end; // Delete a port
mapping if UPnP.DeletePortMapping(8000) = 200 then begin
writeln('Forward deleted ok'); end else begin
writeln('Error deleting forward'); end; end else
Writeln('UPnP is not available.'); UPnP.Free; writeln('we are
done, press enter'); readln; end.
This is the UPNPLibrary unit with class.
It doesn't have the GetPortMap yet but the AddPort and DeletePort work
for me.
If I have some time I can build in those too.
(I wonder if there isn't already such a library floating around... )
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i unit
UPNPLibrary; {$mode objfpc}{$H+} interface uses Classes, SysUtils,
SynaUtil, HTTPSend, blcksock; type TUPnP = class private
FRootXML: string; FBaseURL: string; FControlURL: string;
FServiceType: string; function GetExternalIP: string; function
ExecuteSoapAction(const Action, SoapRequest: string; var SoapResponse:
string): Integer; public constructor Create(const RouterIP:
string); function IsUPnPAvailable: boolean; function
SetPortMapping(const InternalIP: string; InternalPort, ExternalPort:
integer; Protocol: String = 'TCP'; Description: String = ''):
Integer; function DeletePortMapping(const ExternalPort: integer;
Protocol: String = 'TCP'): Integer; property ExternalIP: string
read GetExternalIP; end; implementation function
GetStringBetweenAndStrip(var str: string; startStr, endStr: string):
string;var startPos, endPos: integer;begin startStr :=
uppercase(startStr); endStr := uppercase(endStr); startPos :=
Pos(startStr, uppercase(str)); if startPos = 0 then exit('');
startPos := startPos + Length(startStr); endPos := Pos(endStr,
uppercase(str), startPos); if endPos = 0 then exit(''); Result :=
Copy(str, startPos, endPos - startPos); // strip the string startPos
:= startPos - Length(startStr); endPos := endPos + Length(endStr);
System.Delete(str, startPos, endPos - startPos);end; constructor
TUPnP.Create(const RouterIP: string);var Socket: TUDPBlockSocket; S,
Location, Service: string; Response: TStringList; Cnt:
integer;begin FRootXML := ''; Cnt := 0; S := 'M-SEARCH *
HTTP/1.1'#13#10 + 'HOST: 239.255.255.250:1900'#13#10 + 'MAN:
"ssdp:discover"'#13#10 + 'MX: 3'#13#10 + 'ST:
upnp:rootdevice'#13#10#13#10; Socket := TUDPBlockSocket.Create;
Socket.EnableBroadcast(True); Socket.Connect(RouterIP, '1900');
Socket.SendString(S); repeat Inc(Cnt); if Socket.CanRead(3000)
then begin S := Socket.RecvPacket(3000); if
Pos('LOCATION: ', uppercase(S)) > 0 then begin Location :=
Copy(S, Pos('LOCATION:', uppercase(S)) + 9); Location :=
Trim(Copy(Location, 1, Pos(#13#10, Location) - 1)); Response :=
TStringList.Create; try HttpGetText(Location,
Response); FRootXML := Response.Text; FBaseURL :=
Location; // take base of Location for control while
(FBaseURL <> '') and (Location[Length(FBaseURL)] <> '/') do
Delete(FBaseURL, Length(FBaseURL), 1); if FBaseURL <> '' then
Delete(FBaseURL, Length(FBaseURL), 1); // loop all services
repeat Service :=
GetStringBetweenAndStrip(FRootXML, '', '');
if Pos(uppercase(':WANIPConnection:'), uppercase(service)) > 0
then begin S :=
GetStringBetweenAndStrip(Service, '', '');
if S <> '' then begin Location :=
FBaseURL + S; HttpGetText(Location, Response);
S := Response.Text; if
Pos(uppercase('AddPortMapping'), uppercase(S)) > 0 then
begin FServiceType :=
GetStringBetweenAndStrip(Service, '', '');
S := GetStringBetweenAndStrip(Service, '',
''); FControlURL := FBaseURL + S;
end; end; end; until service
= ''; break; finally Response.Free;
end; end; end; sleep(100); until (Cnt > 1000);
Socket.CloseSocket; Socket.Free; end; function TUPnP.IsUPnPAvailable:
boolean;begin Result := FControlURL <> '';end; function
TUPnP.GetExternalIP: string;var SoapRequest, SoapResponse:
string;begin SoapRequest := '' + '' +
'' + '' + '' + '' +
''; ExecuteSoapAction('GetExternalIPAddress',
SoapRequest, SoapResponse); Result :=
GetStringBetweenAndStrip(SoapResponse, '',
''); end; function TUPnP.SetPortMapping(const
InternalIP: string; InternalPort, ExternalPort: integer; Protocol:
String = 'TCP'; Description: String = ''): Integer;var SoapRequest,
SoapResponse: string;begin SoapRequest := '' + '' +
'' + '' +
'' + '' +
IntToStr(ExternalPort) + '' + '' +
Protocol + '' + '' +
IntToStr(InternalPort) + '' +
'' + InternalIP + '' +
'1' + '' +
Description + '' +
'0' + '' +
'' + ''; Result :=
ExecuteSoapAction('AddPortMapping', SoapRequest,
SoapResponse);end; function TUPnP.DeletePortMapping(const
ExternalPort: integer; Protocol: String = 'TCP'): Integer;var
SoapRequest, SoapResponse: string;begin SoapRequest := '' + '' + '' + '' +
'' + '' +
IntToStr(ExternalPort) + '' + '' +
Protocol + '' + '' +
'' + ''; Result :=
ExecuteSoapAction('DeletePortMapping', SoapRequest,
SoapResponse); end; function TUPnP.ExecuteSoapAction(const Action,
SoapRequest: string; var SoapResponse: string): Integer;var HTTP:
THTTPSend; Response: TStringList;begin Result := -1; HTTP :=
THTTPSend.Create; Response := TStringList.Create; try
HTTP.Headers.Clear; HTTP.Document.Position := 0;
WriteStrToStream(HTTP.Document, SoapRequest); HTTP.MimeType :=
'text/xml; charset="utf-8"'; HTTP.Headers.Add('SOAPAction: "' +
FServiceType + '#' + Action + '"'); if HTTP.HTTPMethod('POST',
FControlURL) then begin
Response.LoadFromStream(HTTP.Document); SoapResponse :=
Response.Text; Result := HTTP.ResultCode; end; finally
HTTP.Free; Response.Free; end;end; end.
----------------------------------------------------------------------
rvk · 2023-06-14 09:54
I have created a upnplib.pas and put it on github with an example.
https://github.com/rvk01/upnp
You can use it to list status info, create port mapping, delete port
mapping and list port mappings.
(Still need to do discovery if the Gateway IP isn't provided)
Output of example program.
QuoteUPnP is available.
Internal IP: 192.168.2.11
External IP: x.x.x.x
Status: Connected
Last error: ERROR_NONE
Uptime router: 23 days, 4 hours 41 minutes and 24 seoconds
SetPortMapping OK
Portmappings:
0 UDP 3332->192.168.2.21:3332 libminiupnpc 0 s
1 UDP 3344->192.168.2.21:4444 test 0 s
2 TCP 8000->192.168.2.11:8081 0 s
Check port. Press Enter to delete and terminate
DeletePortMapping OK
Portmappings:
0 UDP 3332->192.168.2.21:3332 libminiupnpc 0 s
1 UDP 3344->192.168.2.21:4444 test 0 s
We are done, press enter
BTW. Can you check if the UDP entries of yesterday are still there for
you?
For me they are, with lease duration of 0.
----------------------------------------------------------------------
rvk · 2023-06-15 10:21
In the last version I added discovery.
When passing an empty RouterIP (or omit the param in Create) the class
will do a discovery to find the UPnP device.
Latest version is here https://github.com/rvk01/upnp
I haven't found any problems with Lease duration 0 timing out on my
router.
(This version is now done, if there are any comments or suggestions,
they are welcome.)
----------------------------------------------------------------------
Key-Real · 2023-11-21 14:04
Unfortunly the Unit doesn't work under windows!
----------------------------------------------------------------------
rvk · 2023-11-21 14:34
Quote from: Key-Real on November 21, 2023, 03:04:04 pmUnfortunly the
Unit doesn't work under windows!
Sure it does.
But saying it doesn't work doesn't give us much to help you.
----------------------------------------------------------------------
Key-Real · 2023-11-21 14:49
Just tell me that You need, I'll provide the log
----------------------------------------------------------------------
rvk · 2023-11-21 14:52
Quote from: Key-Real on November 21, 2023, 03:49:31 pmJust tell me
that You need, I'll provide the log
You say "doesn't work".
What doesn't work?
Does it compile? If not, what is the compile error?
Do you get an error when running? What error?
Do you get anything?
Please be more specific to what your problem is.
----------------------------------------------------------------------
Key-Real · 2023-11-21 15:23
UPnP.IsUPnPAvailable returns false
----------------------------------------------------------------------
rvk · 2023-11-21 15:28
Quote from: Key-Real on November 21, 2023, 04:23:38
pmUPnP.IsUPnPAvailable returns false
So, are you sure UPNP is enabled on your router?
Still works for me on Windows (had to enable UPNP because I have that
disabled by default on my router).
QuoteUPnP device is available at http://192.168.2.1:45956/ctl/IPConn
Internal IP: 192.168.2.11
External IP: x.x.x.x
Status: Connected
Last error: ERROR_NONE
Uptime router: 45 days 0 hours 58 minutes and 19 seconds
SetPortMapping OK
Portmappings:
0 TCP 8000->192.168.2.11:8081 0 s
Check port. Press Enter to delete and terminate
----------------------------------------------------------------------
Key-Real · 2023-11-21 15:31
it works under the same router configuration under linux
----------------------------------------------------------------------
rvk · 2023-11-21 15:46
Maybe the firewall is blocking the messages?
I've added a debugprocedure for .Create so you can see if you receive
any M-SEARCH messages back from the network.
https://github.com/rvk01/upnp
----------------------------------------------------------------------
Key-Real · 2023-11-21 16:19
procedure debuglog(Value: String);
begin
logwrite(value);
end;
UPnP:= TUPnP.Create('0.0.0.0', @debuglog);
returns:
"M-SEARCH found the following: " [empty string]
----------------------------------------------------------------------
rvk · 2023-11-21 16:28
Quote from: Key-Real on November 21, 2023, 05:19:38 pm"M-SEARCH found
the following: " [empty string]
Then something is blocking the UDP messages from reaching your
program.
Virusscanner? Firewall?
You could try any other program which does a M-SEARCH scan to see if
that works.
Like http://miniupnp.free.fr/ (it has a github page here
https://github.com/miniupnp/miniupnp)
Command "upnpc -L" should provide you with the text "Found valid IGD:
xxx etc".
----------------------------------------------------------------------
Key-Real · 2023-11-21 16:31
can You pls compile it for me?
----------------------------------------------------------------------
Key-Real · 2023-11-21 16:48
mingw gcc returns me errors
----------------------------------------------------------------------
rvk · 2023-11-21 17:10
Quote from: Key-Real on November 21, 2023, 05:31:31 pmcan You pls
compile it for me?
You can download a Windows version on both sites.
For example https://github.com/miniupnp/miniupnp/releases
and here http://miniupnp.free.fr/files/
----------------------------------------------------------------------
Key-Real · 2023-11-21 17:12
$ ./upnpc-shared -l
upnpc : miniupnpc library test client, version 2.1.
(c) 2005-2018 Thomas Bernard.
Go to http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
for more information.
List of UPNP devices found on the network :
desc: http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
st: urn:schemas-upnp-org:device:InternetGatewayDevice:1
Found valid IGD :
http://192.168.0.1:49153/upnp/control/WANIPConnection0
Local LAN ip address : 192.168.0.5
Connection Type : IP_Routed
Status : Connected, uptime=0s, LastConnectionError : ERROR_NONE
MaxBitRateDown : 100000000 bps (100.0 Mbps) MaxBitRateUp 100000000
bps (100.0 Mbps)
ExternalIPAddress = 31.18.189.13
i protocol exPort->inAddr:inPort description remoteHost leaseTime
GetGenericPortMappingEntry() returned 713 (SpecifiedArrayIndexInvalid)
----------------------------------------------------------------------
rvk · 2023-11-21 17:13
Quote from: Key-Real on November 21, 2023, 06:12:47 pm$ ./upnpc-shared
-l
That's on Linux.
Does it work on Windows?
----------------------------------------------------------------------
Key-Real · 2023-11-21 17:14
its on Windows in mingw64 shell
----------------------------------------------------------------------
rvk · 2023-11-21 17:35
Quote from: Key-Real on November 21, 2023, 06:14:51 pmits on Windows
in mingw64 shell
Ai. That's some piece of missing information.
Are you also running the Windows version on mingw64?
Why not just compile on plain Windows with an .exe?
I don't have mingw64 and didn't test that.
----------------------------------------------------------------------
Key-Real · 2023-11-21 17:38
Microsoft Windows [Version 10.0.19045.3570]
(c) Microsoft Corporation. Alle Rechte vorbehalten.
C:\Users\Key-Real>cd C:\Users\Key-Real\Downloads\win32-miniupnpc-2.1
C:\Users\Key-Real\Downloads\win32-miniupnpc-2.1>upnpc-shared.exe -l
upnpc : miniupnpc library test client, version 2.1.
(c) 2005-2018 Thomas Bernard.
Go to http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
for more information.
List of UPNP devices found on the network :
desc: http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
st: urn:schemas-upnp-org:device:InternetGatewayDevice:1
Found valid IGD :
http://192.168.0.1:49153/upnp/control/WANIPConnection0
Local LAN ip address : 192.168.0.5
Connection Type : IP_Routed
Status : Connected, uptime=0s, LastConnectionError : ERROR_NONE
MaxBitRateDown : 100000000 bps (100.0 Mbps) MaxBitRateUp 100000000
bps (100.0 Mbps)
ExternalIPAddress = 31.18.189.13
i protocol exPort->inAddr:inPort description remoteHost leaseTime
GetGenericPortMappingEntry() returned 713 (SpecifiedArrayIndexInvalid)
C:\Users\Key-Real\Downloads\win32-miniupnpc-2.1>
its on windows cmd.exe
----------------------------------------------------------------------
rvk · 2023-11-21 17:43
Quote from: Key-Real on November 21, 2023, 06:38:52 pmC:\Users\Key-
Real>cd C:\Users\Key-Real\Downloads\win32-miniupnpc-2.1
Ok. Then it should also work in FPC with Synapse.
Did you use 0.0.0.0 as ip for calling Create?
You could try the direct ip of the router to see if it makes a
difference.
----------------------------------------------------------------------
Key-Real · 2023-11-21 17:46
no effect
----------------------------------------------------------------------
rvk · 2023-11-21 17:52
Quote from: Key-Real on November 21, 2023, 06:46:28 pmno effect
Then I don't know why it's not working.
You could try to disable the firewall temporarily.
(Just to rule out certain things)
----------------------------------------------------------------------
Key-Real · 2023-11-21 17:59
no effect
----------------------------------------------------------------------
rvk · 2023-11-21 18:04
Quote from: Key-Real on November 21, 2023, 06:59:19 pmno effect
I'm puzzled.
How long does it take before the program ends with no result?
Should at least take a few seconds.
You could change the repeat Cnt > 1 to Cnt > 4 or more in the Create.
----------------------------------------------------------------------
Key-Real · 2023-11-21 18:08
a second
the change has no effect
have to go for a hour, have to by me something to eat...
----------------------------------------------------------------------
balazsszekely · 2023-11-21 18:18
@rvk
Changing the following line in the TUPnP constructor, solves the
issue(at least it did for me):
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i //...
DestAddr.sin_family := AF_INET; DestAddr.sin_port := htons(1900);
DestAddr.sin_addr := StrToNetAddr('255.255.255.255'); //<--this one
DestAddr.sin_addr := StrToNetAddr(RouterIP); //<--to this
fpSendTo(Socket, @S[1], Length(S), 0, @DestAddr, SizeOf(DestAddr));
//..
Now I got a response, later the following line fails:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Service :=
GetStringBetweenAndStrip(S, '', ''); There are no
services at all, but maybe that's just my router.
----------------------------------------------------------------------
rvk · 2023-11-21 18:20
Quote from: Key-Real on November 21, 2023, 07:08:08 pma secondShould
be a least 3 seconds.
With a second there is something wrong with communication/sockets.
I did change the broadcast from 255.255.255.255 to the router IP if
it's provided (it was always 255.255.255.255).
So you can do the test for direct IP again.
But "a second" is too soon for "nothing found".
Quote from: GetMem on November 21, 2023, 07:18:35 pmChanging the
following line in the TUPnP constructor, solves the issue(at least it
did for me):
Yeah, I just found that. That's for passing direct IP of the router.
But 255.255.255.255 broadcast should have worked too.
Quote from: GetMem on November 21, 2023, 07:18:35 pmNow I got a
response, later the following line fails:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Service :=
GetStringBetweenAndStrip(S, '', ''); There are no
services at all, but maybe that's just my router.
Maybe uPNP not enabled
----------------------------------------------------------------------
rvk · 2023-11-21 18:25
Maybe the 255.255.255.255 broadcast doesn't work with all Windows
configurations.
Maybe a routing problem with multiple network interfaces.
https://serverfault.com/questions/72112/how-to-alter-the-global-
broadcast-address-255-255-255-255-behavior-on-windows
Direct router IP with Create should work now in the latest version
https://github.com/rvk01/upnp
@Key-Real: It should also be possible to use 192.168.0.255 (so last
number 255) for broadcast.
BTW. It would be interesting to see your "route print" output.
Especially the 255.255.255.255 addresses at the bottom.
The interface with the lowest metric will get the broadcast.
For me that's my internal IP for my internet access.
Code: Text [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
255.255.255.255 255.255.255.255 On-link 127.0.0.1
331 255.255.255.255 255.255.255.255 On-link
192.168.224.1 5256 255.255.255.255 255.255.255.255 On-link
172.17.0.1 5256 255.255.255.255 255.255.255.255 On-
link 192.168.2.11 281 255.255.255.255 255.255.255.255
On-link 192.168.208.1 5256
Optimum would be to try to send a broadcast to 255.255.255.255 over
ALL interfaces.
I read that Windows XP did that but Windows 7+ not.
----------------------------------------------------------------------
balazsszekely · 2023-11-21 18:34
@rvk
QuoteMaybe uPNP not enabled It is, I double checked. I also ran
upnpc-shared.exe -l which confirms that everything is OK.
After reading you last post, I did try 192.168.0.255 and it works
fine(external IP edited)
QuoteUPnP device is available at http://192.168.0.1:1900/ipc
Internal IP: 192.168.79.1
External IP: X.X.X.X
Status: Connected
Last error: ERROR_NONE
Uptime router: 0 days 0 hours 0 minutes and 0 seconds
SetPortMapping OK
Portmappings:
0 TCP 8000->192.168.79.1:8081 0 s
Check port. Press Enter to delete and terminate
Surprisingly 192.168.0.1, the router IP address is not working.
----------------------------------------------------------------------
rvk · 2023-11-21 18:39
Quote from: GetMem on November 21, 2023, 07:34:05 pmQuoteMaybe uPNP
not enabled It is, I double checked. I also ran upnpc-shared.exe -l
which confirms that everything is fine with UPnP.
After reading you last post, I did try 192.168.1.255 and it works
fine(external IP edited)
(..)
Surprisingly 192.168.0.1, the router IP address is not working.
Maybe the first M-SEARCH result from the 192.168.0.1 doesn't contain
the services.
That's why the Cnt counter is reset when LOCATION is found until there
is one where services is included.
Did your first M-SEARCH result from 192.168.0.1 contain a LOCATION
header?
If it does not, and there are more than 1 such devices (like
multimedia devices) the scan could end prematurely.
I might need to rethink the SCAN function. It was designed to not wait
too long for a result if there is no uPnp device on the network.
But that's a balancing act (for waiting until you DO need to find
one)
If there are M-SEARCH messages without a LOCATION header I just need
to check if Message <> '' and then reset the Cnt to 0 for that.
----------------------------------------------------------------------
rvk · 2023-11-21 18:46
Changed the SCAN function to reset the Cnt counter to 0 when there is
any M-SEARCH message.
So just a simple binary response (which can happen) will not increase
the counter and the wait for router can continue.
https://github.com/rvk01/upnp
----------------------------------------------------------------------
balazsszekely · 2023-11-21 18:52
QuoteMaybe the first M-SEARCH result from the 192.168.0.1 doesn't
contain the services.
That's why the Cnt counter is reset when LOCATION is found until there
is one where services is included.Yes. I double checked again and
there are no services when connecting with 192.168.0.1
QuoteDid your first M-SEARCH result from 192.168.0.1 contain a
LOCATION header?Yes.
QuoteChanged the SCAN function to reset the Cnt counter to 0 when
there is any M-SEARCH message.
So just a simple binary response (which can happen) will not increase
the counter and the wait for router can continue.With you new
modification I got this(192.168.0.1):
Quote debug --> M-SEARCH found the following:
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1801
DATE: Tue, 21 Nov 2023 18:50:00 GMT
EXT:
LOCATION: http://192.168.0.1:49152/wps_device.xml
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: upnp:rootdevice
USN: uuid:00000000-0000-1000-0000-50c7bf396fa2::upnp:rootdevice
debug --> M-SEARCH found the following:
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1801
DATE: Tue, 21 Nov 2023 18:50:00 GMT
EXT:
LOCATION: http://192.168.0.1:49152/wps_device.xml
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: upnp:rootdevice
USN: uuid:00000000-0000-1000-0000-50c7bf396fa2::upnp:rootdevice
debug --> M-SEARCH found the following:
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1801
DATE: Tue, 21 Nov 2023 18:50:00 GMT
EXT:
LOCATION: http://192.168.0.1:49152/wps_device.xml
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: uuid:00000000-0000-1000-0000-50c7bf396fa2
USN: uuid:00000000-0000-1000-0000-50c7bf396fa2
debug --> M-SEARCH found the following:
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1801
DATE: Tue, 21 Nov 2023 18:50:00 GMT
EXT:
LOCATION: http://192.168.0.1:49152/wps_device.xml
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: uuid:00000000-0000-1000-0000-50c7bf396fa2
USN: uuid:00000000-0000-1000-0000-50c7bf396fa2
debug --> M-SEARCH found the following:
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1801
DATE: Tue, 21 Nov 2023 18:50:00 GMT
EXT:
LOCATION: http://192.168.0.1:49152/wps_device.xml
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: urn:schemas-wifialliance-org:device:WFADevice:1
USN: uuid:00000000-0000-1000-0000-50c7bf396fa2::urn:schemas-
wifialliance-org:device:WFADevice:1
debug --> M-SEARCH found the following:
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1801
DATE: Tue, 21 Nov 2023 18:50:00 GMT
EXT:
LOCATION: http://192.168.0.1:49152/wps_device.xml
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: urn:schemas-wifialliance-org:device:WFADevice:1
USN: uuid:00000000-0000-1000-0000-50c7bf396fa2::urn:schemas-
wifialliance-org:device:WFADevice:1
debug --> M-SEARCH found the following:
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1801
DATE: Tue, 21 Nov 2023 18:50:00 GMT
EXT:
LOCATION: http://192.168.0.1:49152/wps_device.xml
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: urn:schemas-wifialliance-org:service:WFAWLANConfig:1
USN: uuid:00000000-0000-1000-0000-50c7bf396fa2::urn:schemas-
wifialliance-org:service:WFAWLANConfig:1
debug --> M-SEARCH found the following:
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1801
DATE: Tue, 21 Nov 2023 18:50:00 GMT
EXT:
LOCATION: http://192.168.0.1:49152/wps_device.xml
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: urn:schemas-wifialliance-org:service:WFAWLANConfig:1
USN: uuid:00000000-0000-1000-0000-50c7bf396fa2::urn:schemas-
wifialliance-org:service:WFAWLANConfig:1
debug --> M-SEARCH found the following:
debug --> M-SEARCH found the following:
debug --> M-SEARCH found the following:
debug --> M-SEARCH found the following:
UPnP is not available.
We are done, press enter
192.168.0.255 works as before.
----------------------------------------------------------------------
rvk · 2023-11-21 19:00
Quote from: GetMem on November 21, 2023, 07:52:36 pmLOCATION:
http://192.168.0.1:49152/wps_device.xml
The program retrieves the xml on that location and checks the
services.
One of them should contain WANIPConnection for uPnp enabled device.
My last modification I had put the counter to 300 just to test the
delay.
Should work correctly now.
I also added the result of the xml from the retrieved location.
Might be too much debugging for a normal program but the writeln in
debugproc could just be removed then.
Still need to find out how to access all the interfaces.
Problem might be with that, is it needs to be done after each other or
you need to look at threading, and this was just to show the M-SEARCH
mechanism without the need for more complex threading code.
----------------------------------------------------------------------
Key-Real · 2023-11-21 19:25
with the new version of your lib it returns me:
"M-SEARCH nothing found yet"
----------------------------------------------------------------------
rvk · 2023-11-21 19:28
Quote from: Key-Real on November 21, 2023, 08:25:12 pmwith the new
version of your lib it returns me:
"M-SEARCH nothing found yet"
Did you try 192.168.0.255 as address?
And 192.168.0.1 ?
----------------------------------------------------------------------
Key-Real · 2023-11-21 19:35
UPnP:= TUPnP.Create('192.168.0.255', @debuglog);
gives me this:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i M-SEARCH
found the following (length 438 bytes): HTTP/1.1 200 OKCACHE-CONTROL:
max-age=1800DATE: Tue, 21 Nov 2023 19:32:53 GMTEXT:LOCATION:
http://192.168.0.1:49153/IGDdevicedesc_brlan0.xmlOPT:
"http://schemas.upnp.org/upnp/1/0/"; ns=0101-NLS:
2f4379a0-88a0-11ee-94ec-86845e9bdfd5SERVER: Linux/4.9.135-Prod_19.3,
UPnP/1.0, Portable SDK for UPnP devices/1.6.22X-User-Agent:
redsonicST: upnp:rootdeviceUSN:
uuid:ebf5a0a0-1dd1-11b2-a90f-021018951e6c::upnp:rootdevice M-SEARCH
result:10
urn:schemas-upnp-org:device:InternetGatewayDevice:1CGA6444VFTechnicolor<
/manufacturer>http://www.technicolor.com/Docsis 3.1 GatewayCGA6444VF1.0http://
www.technicolor.comuuid:e
bf5a0a0-1dd1-11b2-a90f-
021018951e6cCGA6444VFurn:schemas-upnp-
org:service:Layer3Forwarding:1urn:upnp-org:se
rviceId:L3Forwarding1/Layer3ForwardingSCPD.xml/upnp/control/Layer3Forwarding/upnp/event/Layer3Forwardingurn:schemas-upnp-org:device:WANDevice
:1WANDevice:1T
echnicolorhttp://www.technicolor.com/<
/manufacturerURL>Docsis 3.1 GatewayCGA6444VF1.0http://www.technicolor.com
uuid:ebf5a0a0-1dd1-11b2-a92f-
021018951e6cCGA6444VFurn:schemas-upnp-org:service:WANCommonInterfaceConfig:1urn:upnp-org:serviceId:WANCommonIFC1
/WANCommonInterfaceConfigSCPD.xml/upnp/control/W
ANCommonInterfaceConfig0/upnp/event/WANCommo
nInterfaceConfig0
urn:schemas-upnp-
org:device:WANConnectionDevice:1
WANConnectionDevice:1
Technicolor
http://www.technicolor.com/
Docsis 3.1 Gateway
CGA6444VF
1.0
http://www.technicolor.com
uuid:ebf5a0a0-1dd1-11b2-a93f-021018951e6c
CGA6444VF
urn:schemas-upnp-
org:service:WANIPConnection:1
urn:upnp-org:serviceId:WANIPConn1
/WANIPConnectionServiceSCPD.xml
/upnp/control/WANIPConnection0
/upnp/event/WANIPConnection0
deviceList>http://192.168.0.1/ UPnP device is available at
http://192.168.0.1:49153/upnp/control/WANIPConnection0Internal IP:
192.168.56.1External IP: 31.18.189.13Status: ConnectedLast error:
ERROR_NONEUptime router: 0 days 0 hours 0 minutes and 0 secondsError
SetPortMappingResultCode: 500
s:ClientUPnPError402PAL_UPNP_SOAP_E_INVALID
_ARGS Error SetPortMappingResultCode: 500
s:ClientUPnPError402PAL_UPNP_SOAP_E_INVALID
_ARGS
----------------------------------------------------------------------
rvk · 2023-11-21 19:40
Quote from: Key-Real on November 21, 2023, 08:35:43 pmUPnP:=
TUPnP.Create('192.168.0.255', @debuglog);
Ok. That one finds the router but gives you errors on setting the port
forwarding.
What did you pass to UPnP.SetPortMapping() ??
The router gives PAL_UPNP_SOAP_E_INVALID_ARGS back on those arguments.
----------------------------------------------------------------------
Key-Real · 2023-11-21 19:41
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
setupUPnP;var Status : string; LastError : string; Uptime :
integer; aDialog : TtuiDialogMessageBox; error : boolean; begin
upnpinstalled:= false; error:= false;
log('Setuping UPnP...'); UPnP:= TUPnP.Create('192.168.0.255',
@debuglog); try if UPnP.IsUPnPAvailable then begin
log('UPnP device is available at ' + UPnP.ControlURL);
UPnP.GetStatusInfo(Status, LastError, Uptime); log('Internal IP:
' + UPnP.InternalIP); log('External IP: ' + UPnP.ExternalIP);
log('Status: ' + Status); log('Last error: ' + LastError);
log('Uptime router: ' + format('%d days %d hours %d minutes and %d
seconds', [Uptime div 86400, (Uptime div 3600) mod 24, (Uptime div 60)
mod 60, Uptime mod 60])); if
UPnP.SetPortMapping(UPnP.InternalIP, ServerPORT, ServerPORT, 'TCP',
'FlyTracker') then begin if
UPnP.GetSpecificPortMapping(ServerPORT, 'TCP').InternalClient =
UPnP.InternalIP then log('SetPortMapping OK') else
begin log('SetPortMapping reports OK but Port does not seem
to be forwarded'); error:= true; end;
RefreshAndPrintPortMappings; upnpinstalled:=true; end
else begin log('Error SetPortMapping' + LineEnding +
'ResultCode: ' + UPNP.LastResultCode.ToString + LineEnding +
UPnP.LastResponse); error:= true; end; if
UPnP.SetPortMapping(UPnP.InternalIP, ServerPORT, ServerPORT, 'UDP',
'FlyTracker') then begin if
UPnP.GetSpecificPortMapping(ServerPORT, 'UDP').InternalClient =
UPnP.InternalIP then log('SetPortMapping OK') else
begin log('SetPortMapping reports OK but Port does not seem
to be forwarded'); error:= true; end;
RefreshAndPrintPortMappings; upnpinstalled:=true; end
else begin log('Error SetPortMapping' + LineEnding +
'ResultCode: ' + UPNP.LastResultCode.ToString + LineEnding +
UPnP.LastResponse); error:= true; end; end else
error:= true; finally end; if error then begin
log('UPnP Error!'); if currentMode = modeTracker then
aDialog:= TtuiDialogMessageBox.Create(@aDialog, TrackerTUI, 'UPnP is
not available'); if currentMode = modeInstrumentEditor then
aDialog:= TtuiDialogMessageBox.Create(@aDialog, InstrumentEditorTUI,
'UPnP is not available'); end; end;
----------------------------------------------------------------------
rvk · 2023-11-21 19:51
Quote from: Key-Real on November 21, 2023, 08:41:53 pmWhat happens if
you put the RefreshAndPrintPortMappings above the SetPortMapping?
How many ports are forwarded?
PAL_UPNP_SOAP_E_INVALID_ARGS seems to indicate that there are too
many.
https://github.com/miniupnp/miniupnp/issues/92
And what did you put into ServerPORT?
Is that port available?
Can you port forward with win32-miniupnpc-2.1?
----------------------------------------------------------------------
Key-Real · 2023-11-21 19:59
ServerPort is 1234
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
RefreshAndPrintPortMappings;var s : string; i : integer; begin
if not UPnP.RefreshPortMapping then log('Error
RefreshPortMapping' + LineEnding + 'ResultCode: ' +
UPNP.LastResultCode.ToString + LineEnding + UPnP.LastResponse); if
Length(UPnP.PortMappings) > 0 then begin log('Portmappings:');
for i:= 0 to Length(UPnP.PortMappings) - 1 do begin
with UPnP.PortMappings[i] do S:= Format('%d %s %d->%s:%d %s
%d s', [i, Protocol, ExternalPort, InternalClient, InternalPort,
Description, LeaseDuration]); log(S); end; end
else log('No portmappings'); end;
RefreshAndPrintPortMappings;
before
if UPnP.SetPortMapping(UPnP.InternalIP, ServerPORT, ServerPORT, 'TCP',
'FlyTracker') then begin ....
tells me:
'No portmappings'
----------------------------------------------------------------------
rvk · 2023-11-21 20:03
Quote from: Key-Real on November 21, 2023, 08:59:02 pmServerPort is
1234
Does this work with miniupnpc ?
win32-miniupnpc-2.1 -a 192.168.56.1 1234 1234 TCP
I do find that local internal IP for your PC also strange 192.168.56.1
??
If your router is 192.168.0.1 I think that's a wrong internal IP.
----------------------------------------------------------------------
Key-Real · 2023-11-21 20:04
$ ./upnpc-shared.exe -a 192.168.0.5 1234 1234 TCP
upnpc : miniupnpc library test client, version 2.1.
(c) 2005-2018 Thomas Bernard.
Go to http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
for more information.
List of UPNP devices found on the network :
desc: http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml
st: urn:schemas-upnp-org:device:InternetGatewayDevice:1
Found valid IGD :
http://192.168.0.1:49153/upnp/control/WANIPConnection0
Local LAN ip address : 192.168.0.5
ExternalIPAddress = 31.18.189.13
InternalIP:Port = 192.168.0.5:1234
external 31.18.189.13:1234 TCP is redirected to internal
192.168.0.5:1234 (duration=0)
----------------------------------------------------------------------
rvk · 2023-11-21 20:06
Quote from: Key-Real on November 21, 2023, 09:04:27 pmLocal LAN ip
address : 192.168.0.5
I do find that local internal IP for your PC also strange 192.168.56.1
??
It's detected from your HOSTNAME.
If your router is 192.168.0.1 I think that's a wrong internal IP.
Could you change the UPnP.InternalIP in that call for SetPortMapping
to your correct internal IP.
I think you have a 'weird' internal network (with 255.255.255.255
mapping and internet interfaces).
What does this give you?
ping %USERDOMAIN% -4
Edit:
I use this code to get the internal IP.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i function
TUPnP.GetInternalIP: string;var HostName: AnsiString; HostEntry:
PHostEnt;begin Result := ''; HostName := ''; SetLength(HostName,
255); if GetHostName(PAnsiChar(HostName), Length(HostName)) = 0 then
begin SetLength(HostName, StrLen(PAnsiChar(HostName)));
HostEntry := GetHostByName(PAnsiChar(HostName)); if
Assigned(HostEntry) then Result :=
StrPas(inet_ntoa(PInAddr(HostEntry^.h_addr_list^)^)); end;end;
Maybe that detection is wrong.
----------------------------------------------------------------------
Key-Real · 2023-11-21 20:26
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i if
UPnP.SetPortMapping('192.168.0.5', ServerPORT, ServerPORT, 'TCP',
'FlyTracker') then begin
gives me:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Connecting
through UPnP....Setuping UPnP...M-SEARCH found the following (length
438 bytes): HTTP/1.1 200 OKCACHE-CONTROL: max-age=1800DATE: Tue, 21
Nov 2023 20:09:18 GMTEXT:LOCATION:
http://192.168.0.1:49153/IGDdevicedesc_brlan0.xmlOPT:
"http://schemas.upnp.org/upnp/1/0/"; ns=0101-NLS:
7916dd96-88a6-11ee-855f-ea9443b3f8d1SERVER: Linux/4.9.135-Prod_19.3,
UPnP/1.0, Portable SDK for UPnP devices/1.6.22X-User-Agent:
redsonicST: upnp:rootdeviceUSN:
uuid:ebf5a0a0-1dd1-11b2-a90f-021018951e6c::upnp:rootdevice M-SEARCH
result:10
urn:schemas-upnp-org:device:InternetGatewayDevice:1CGA6444VFTechnicolor<
/manufacturer>http://www.technicolor.com/Docsis 3.1 GatewayCGA6444VF1.0http://
www.technicolor.comuuid:e
bf5a0a0-1dd1-11b2-a90f-
021018951e6cCGA6444VFurn:schemas-upnp-
org:service:Layer3Forwarding:1urn:upnp-org:se
rviceId:L3Forwarding1/Layer3ForwardingSCPD.xml/upnp/control/Layer3Forwarding/upnp/event/Layer3Forwardingurn:schemas-upnp-org:device:WANDevice
:1WANDevice:1T
echnicolorhttp://www.technicolor.com/<
/manufacturerURL>Docsis 3.1 GatewayCGA6444VF1.0http://www.technicolor.com
uuid:ebf5a0a0-1dd1-11b2-a92f-
021018951e6cCGA6444VFurn:schemas-upnp-org:service:WANCommonInterfaceConfig:1urn:upnp-org:serviceId:WANCommonIFC1
/WANCommonInterfaceConfigSCPD.xml/upnp/control/W
ANCommonInterfaceConfig0/upnp/event/WANCommo
nInterfaceConfig0
urn:schemas-upnp-
org:device:WANConnectionDevice:1
WANConnectionDevice:1
Technicolor
http://www.technicolor.com/
Docsis 3.1 Gateway
CGA6444VF
1.0
http://www.technicolor.com
uuid:ebf5a0a0-1dd1-11b2-a93f-021018951e6c
CGA6444VF
urn:schemas-upnp-
org:service:WANIPConnection:1
urn:upnp-org:serviceId:WANIPConn1
/WANIPConnectionServiceSCPD.xml
/upnp/control/WANIPConnection0
/upnp/event/WANIPConnection0
deviceList>http://192.168.0.1/ UPnP device is available at
http://192.168.0.1:49153/upnp/control/WANIPConnection0Internal IP:
192.168.56.1External IP: 31.18.189.13Status: ConnectedLast error:
ERROR_NONEUptime router: 0 days 0 hours 0 minutes and 0 secondsNo
portmappingsOpening Port...SetPortMapping reports OK but Port does not
seem to be forwardedPortmappings:0 TCP 1234->192.168.0.5:1234
FlyTracker 0 sSetPortMapping reports OK but Port does not seem to be
forwardedPortmappings:0 TCP 1234->192.168.0.5:1234 FlyTracker 0 s1 UDP
1234->192.168.0.5:1234 FlyTracker 0 sUPnP Error!
the new function TUPnP.GetInternalIP: string;
gives me still the wrong ip.
the ping tells me : can't find %USERDOMAIN%
----------------------------------------------------------------------
rvk · 2023-11-21 20:29
Quote from: Key-Real on November 21, 2023, 09:26:24 pmCode: Pascal
[Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i if
UPnP.SetPortMapping('192.168.0.5', ServerPORT, ServerPORT, 'TCP',
'FlyTracker') then begin
{.......}
SetPortMapping reports OK but Port does not seem to be forwarded
Portmappings:
0 TCP 1234->192.168.0.5:1234 FlyTracker 0 s
SetPortMapping reports OK but Port does not seem to be forwarded
Portmappings:
0 TCP 1234->192.168.0.5:1234 FlyTracker 0 s
1 UDP 1234->192.168.0.5:1234 FlyTracker 0 s
UPnP Error!
[/code]
You need to remove the current 1234 you did with minupnpc.
Otherwise it doesn't work. You can't add a portforward which already
exists.
Quote from: Key-Real on November 21, 2023, 09:26:24 pmthe new function
TUPnP.GetInternalIP: string;
gives me still the wrong ip.
the ping tells me : can't find %USERDOMAIN%
Can you do the command "set" and see which environment variable
contains your computername.
End result would be "ping yourcomputername -4" to see what IP you get.
This should be 192.168.0.5. If it gives you 192.168.56.1 it's the same
problem as the GetHostByName in FPC.
----------------------------------------------------------------------
Key-Real · 2023-11-21 20:36
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i $ ping
DESKTOP-B8UVQV5 -4 Ping wird ausgef▒hrt f▒r DESKTOP-B8UVQV5
[192.168.56.1] mit 32 Bytes Daten:Antwort von 192.168.56.1: Bytes=32
Zeit<1ms TTL=128Antwort von 192.168.56.1: Bytes=32 Zeit<1ms
TTL=128Antwort von 192.168.56.1: Bytes=32 Zeit<1ms TTL=128Antwort von
192.168.56.1: Bytes=32 Zeit<1ms TTL=128 Ping-Statistik f▒r
192.168.56.1: Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
(0% Verlust),Ca. Zeitangaben in Millisek.: Minimum = 0ms, Maximum =
0ms, Mittelwert = 0ms
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i $ ./upnpc-
shared.exe -d 1234 TCPupnpc : miniupnpc library test client, version
2.1. (c) 2005-2018 Thomas Bernard.Go to http://miniupnp.free.fr/ or
https://miniupnp.tuxfamily.org/for more information.List of UPNP
devices found on the network : desc:
http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml st: urn:schemas-
upnp-org:device:InternetGatewayDevice:1 Found valid IGD :
http://192.168.0.1:49153/upnp/control/WANIPConnection0Local LAN ip
address : 192.168.0.5UPNP_DeletePortMapping() failed with code : 714
----------------------------------------------------------------------
rvk · 2023-11-21 20:39
Quote from: Key-Real on November 21, 2023, 09:36:18 pmCode: Pascal
[Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i $ ping
DESKTOP-B8UVQV5 -4 Ping wird ausgef▒hrt f▒r DESKTOP-B8UVQV5
[192.168.56.1] mit 32 Bytes Daten:Antwort von 192.168.56.1: Bytes=32
Zeit<1ms TTL=128What kind of IP range is 192.168.56.x for you?
If your router is on 192.168.0.1 I would expect that "ping
yourhostname -4" would result in your own 192.168.0.5.
So that's really strange. Is that maybe a VPN ??
Quote from: Key-Real on November 21, 2023, 09:36:18 pm$ ./upnpc-
shared.exe -d 1234 TCP
(.....)
UPNP_DeletePortMapping() failed with code : 714
Does ./upnpc-shared.exe -l still show the 1234 forwardings for TCP and
UDP?
----------------------------------------------------------------------
Key-Real · 2023-11-21 20:42
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i $ ./upnpc-
shared.exe -lupnpc : miniupnpc library test client, version 2.1. (c)
2005-2018 Thomas Bernard.Go to http://miniupnp.free.fr/ or
https://miniupnp.tuxfamily.org/for more information.List of UPNP
devices found on the network : desc:
http://192.168.0.1:49153/IGDdevicedesc_brlan0.xml st: urn:schemas-
upnp-org:device:InternetGatewayDevice:1 Found valid IGD :
http://192.168.0.1:49153/upnp/control/WANIPConnection0Local LAN ip
address : 192.168.0.5Connection Type : IP_RoutedStatus : Connected,
uptime=0s, LastConnectionError : ERROR_NONEMaxBitRateDown : 100000000
bps (100.0 Mbps) MaxBitRateUp 100000000 bps (100.0
Mbps)ExternalIPAddress = 31.18.189.13 i protocol exPort->inAddr:inPort
description remoteHost leaseTimeGetGenericPortMappingEntry() returned
713 (SpecifiedArrayIndexInvalid)
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i $
ipconfig Windows-IP-Konfiguration Ethernet-Adapter Ethernet:
Verbindungsspezifisches DNS-Suffix: Verbindungslokale IPv6-Adresse
. : fe80::b61d:8d7e:c75b:e740%32 IPv4-Adresse . . . . . . . . . .
: 192.168.0.5 Subnetzmaske . . . . . . . . . . : 255.255.255.0
Standardgateway . . . . . . . . . : 192.168.0.1 Ethernet-Adapter
Ethernet 2: Verbindungsspezifisches DNS-Suffix: Verbindungslokale
IPv6-Adresse . : fe80::9842:6014:cefe:6915%7 IPv4-Adresse . . . .
. . . . . . : 192.168.56.1 Subnetzmaske . . . . . . . . . . :
255.255.255.0 Standardgateway . . . . . . . . . : Drahtlos-LAN-
Adapter WLAN: Medienstatus. . . . . . . . . . . : Medium getrennt
Verbindungsspezifisches DNS-Suffix: Drahtlos-LAN-Adapter LAN-
Verbindung* 9: Medienstatus. . . . . . . . . . . : Medium getrennt
Verbindungsspezifisches DNS-Suffix: Drahtlos-LAN-Adapter LAN-
Verbindung* 10: Medienstatus. . . . . . . . . . . : Medium
getrennt Verbindungsspezifisches DNS-Suffix:
no VPN
----------------------------------------------------------------------
rvk · 2023-11-21 20:46
Quote from: Key-Real on November 21, 2023, 09:42:01 pmCode: Pascal
[Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i $ ./upnpc-
shared.exe -lGetGenericPortMappingEntry() returned 713
(SpecifiedArrayIndexInvalid) Ok, it could be that the first run the
mapping already existed.
But the mapping could be deleted afterwards.
So it should be ok now (if you run it again).
Quote from: Key-Real on November 21, 2023, 09:42:01 pm
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Ethernet-
Adapter Ethernet 2: Verbindungsspezifisches DNS-Suffix:
Verbindungslokale IPv6-Adresse . : fe80::9842:6014:cefe:6915%7
IPv4-Adresse . . . . . . . . . . : 192.168.56.1 Subnetzmaske . .
. . . . . . . . : 255.255.255.0 Standardgateway . . . . . . . . . :
no VPN
So no VPN. But what is on "Ethernet-Adapter Ethernet 2" ???
Probably your output or route print also has the lower metric for
255.255.255.255 on that interface and that's why the broadcast on
255.255.255.255 didn't find the router.
So your Internet card 2 has higher proirity over that of your router.
Normally that indicates a VPN.
If I were you I would find out why you have a Internet 2 (before
someone is spying on your internet traffic).
----------------------------------------------------------------------
rvk · 2023-11-21 20:49
I have some extra network interfaces for Hyper-V but none have a
higher priority from my internet connection.
But this could be a bridge network interface which messes everything
up.
(Traffic over 192.168.56.1 would pass through to your 192.168.0.x but
for gethostname and broadcast this is not easy to detect)
----------------------------------------------------------------------
Key-Real · 2023-11-21 20:51
I have no idea where the Ethernet 2 is came from!
If I wanna conncet local only 192.168.0.5 works
----------------------------------------------------------------------
rvk · 2023-11-21 20:53
Quote from: Key-Real on November 21, 2023, 09:51:34 pmIf I wanna
conncet local only 192.168.0.5 works
Yep, if you do Create with 192.168.0.255 and SetPortMapping with
192.168.0.5 (your internal IP) it should work correctly.
Automatic detection of 255.255.255.255 broadcast doesn't work with a
bridge adapter (like one for Hyper-V)
and UPnP.InternalIP (which returns the IP for your bridge adapter
which isn't known in your router so gives an error).
----------------------------------------------------------------------
Key-Real · 2023-11-21 20:57
I Create with 192.168.0.255 and SetPortMapping with 192.168.0.5
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Connecting
through UPnP....Setuping UPnP...M-SEARCH found the following (length
438 bytes): HTTP/1.1 200 OKCACHE-CONTROL: max-age=1800DATE: Tue, 21
Nov 2023 20:56:51 GMTEXT:LOCATION:
http://192.168.0.1:49153/IGDdevicedesc_brlan0.xmlOPT:
"http://schemas.upnp.org/upnp/1/0/"; ns=0101-NLS:
c2893784-88ac-11ee-9ee8-a235e7bf7181SERVER: Linux/4.9.135-Prod_19.3,
UPnP/1.0, Portable SDK for UPnP devices/1.6.22X-User-Agent:
redsonicST: upnp:rootdeviceUSN:
uuid:ebf5a0a0-1dd1-11b2-a90f-021018951e6c::upnp:rootdevice M-SEARCH
result:10
urn:schemas-upnp-org:device:InternetGatewayDevice:1CGA6444VFTechnicolor<
/manufacturer>http://www.technicolor.com/Docsis 3.1 GatewayCGA6444VF1.0http://
www.technicolor.comuuid:e
bf5a0a0-1dd1-11b2-a90f-
021018951e6cCGA6444VFurn:schemas-upnp-
org:service:Layer3Forwarding:1urn:upnp-org:se
rviceId:L3Forwarding1/Layer3ForwardingSCPD.xml/upnp/control/Layer3Forwarding/upnp/event/Layer3Forwardingurn:schemas-upnp-org:device:WANDevice
:1WANDevice:1T
echnicolorhttp://www.technicolor.com/<
/manufacturerURL>Docsis 3.1 GatewayCGA6444VF1.0http://www.technicolor.com
uuid:ebf5a0a0-1dd1-11b2-a92f-
021018951e6cCGA6444VFurn:schemas-upnp-org:service:WANCommonInterfaceConfig:1urn:upnp-org:serviceId:WANCommonIFC1
/WANCommonInterfaceConfigSCPD.xml/upnp/control/W
ANCommonInterfaceConfig0/upnp/event/WANCommo
nInterfaceConfig0
urn:schemas-upnp-
org:device:WANConnectionDevice:1
WANConnectionDevice:1
Technicolor
http://www.technicolor.com/
Docsis 3.1 Gateway
CGA6444VF
1.0
http://www.technicolor.com
uuid:ebf5a0a0-1dd1-11b2-a93f-021018951e6c
CGA6444VF
urn:schemas-upnp-
org:service:WANIPConnection:1
urn:upnp-org:serviceId:WANIPConn1
/WANIPConnectionServiceSCPD.xml
/upnp/control/WANIPConnection0
/upnp/event/WANIPConnection0
deviceList>http://192.168.0.1/ UPnP device is available at
http://192.168.0.1:49153/upnp/control/WANIPConnection0Internal IP:
192.168.56.1External IP: 31.18.189.13Status: ConnectedLast error:
ERROR_NONEUptime router: 0 days 0 hours 0 minutes and 0 secondsNo
portmappingsOpening Port...SetPortMapping reports OK but Port does not
seem to be forwardedPortmappings:0 TCP 1234->192.168.0.5:1234
FlyTracker 0 sSetPortMapping reports OK but Port does not seem to be
forwardedPortmappings:0 TCP 1234->192.168.0.5:1234 FlyTracker 0 s1 UDP
1234->192.168.0.5:1234 FlyTracker 0 sUPnP Error!
SetPortMapping reports OK but Port does not seem to be forwarded!
----------------------------------------------------------------------
Key-Real · 2023-11-21 20:59
btw.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {$IFDEF
WINDOWS} {$HINTS OFF} WSAStartup(2, VWSAData);
{$HINTS ON} SetLength(VName, 255);
GetHostName(PChar(VName), 255); SetLength(VName,
StrLen(PChar(VName))); VHostEnt :=
GetHostByName(PChar(VName)); with VHostEnt^ do Result :=
Format(CFormatIPMask, [Byte(h_addr^[0]), Byte(h_addr^[1]),
Byte(h_addr^[2]), Byte(h_addr^[3])]);
WSACleanup; {$ENDIF} end;
returns me 192.168.56.1
----------------------------------------------------------------------
rvk · 2023-11-21 20:59
Code: [Select][quote author=Key-Real
link=topic=63652.msg497522#msg497522 date=1700600274]
Portmappings:
0 TCP 1234->192.168.0.5:1234 FlyTracker 0 s
1 UDP 1234->192.168.0.5:1234 FlyTracker 0 s
UPnP Error!
SetPortMapping reports OK but Port does not seem to be forwarded!
[/quote]
It works fine but you have this line:
if UPnP.GetSpecificPortMapping(8000, 'TCP').InternalClient =
UPnP.InternalIP then
Of course you need to replace the InternalIP there too with
192.168.0.5
----------------------------------------------------------------------
rvk · 2023-11-21 21:01
Quote from: Key-Real on November 21, 2023, 09:59:11 pmreturns me
192.168.56.1
Yes, and that's an internal IP for a bridge adapter. It's not known at
your router (which is why InternalIp doesn't work).
----------------------------------------------------------------------
Key-Real · 2023-11-21 21:06
ok, i changed everyting but my app still cant connect
----------------------------------------------------------------------
Key-Real · 2023-11-21 21:07
where is the "strange" ip came from? How to find this out? Im not a
windows pro.
----------------------------------------------------------------------
rvk · 2023-11-21 21:11
Quote from: Key-Real on November 21, 2023, 10:07:08 pmwhere is the
"strange" ip came from? How to find this out? Im not a windows pro.
Click the notification area and click all settings.
Goto Network & Internet
Click Ethernet
Click "Change adapter options"
Now you see all the network connections.
There are probably some Hyper-V Virtual Ethernet Adapters
Quote from: Key-Real on November 21, 2023, 10:06:04 pmok, i changed
everyting but my app still cant connect
If the portforwarding is correct now then the upnp library works
correctly.
It's upto the code for listening for the incoming connection for it to
work.
But the virtual adapter can mess things up there too (but that depends
on that code).
----------------------------------------------------------------------
Key-Real · 2023-11-21 22:08
Good News:
Yes I had a VirtualBox "something" in the list.
I disabled it.
now the returned local IP is correct.
is seems to do the forwarding.
the bad news:
My network routies did not work under windows (microsoft sux) have
to check where the issues are.
well BIG THX!!!!!!!!