[win xp] UPnP

Share your advanced PureBasic knowledge/code with the community.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

[win xp] UPnP

Post by lexvictory »

i know some of you like to disable UPnP on windows xp, but i use it, so i have implemented the interfaces to control a router using UPnP (xp only)

u can download the include file and and example file Here
the example code only finds router(s) and then displays all of the mapped ports on it, but the other bits shouldnt be hard to work out.
example code is also very messy.... but thats because i translated it from c++...

this is first time ive had to define interfaces and then get them working....
the code works in both unicode and ascii modes :D
Last edited by lexvictory on Thu Nov 30, 2006 7:39 am, edited 1 time in total.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

Link doesn't work.
bye,
Daniel
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

grr, it did that to me the first time i tested it, then it worked....

gimme a sec and i'll put it on a different host
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

ok, link updated in first post

it was coz the first host i had it on is a sometimes stupid free host....
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

yes this code is very ugly, and seams very unsafe
Line 40: - Invalid memory access.

Code: Select all

If piPortMappingCollection\get__NewEnum(@piUnk) = #S_OK
it dies as the result of Line 36

Code: Select all

nat\get_StaticPortMappingCollection(@piPortMappingCollection.IStaticPortMappingCollection)
the function did not create the piPortMappingCollection Interface and left as null
it also does not return anything so testing it for #S_OK does nothing
but it does post an error into system which reads
The requested lookup key was not found in any active activation context.
I'm not sure what it means...
~Dreglor
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

Dreglor wrote: I'm not sure what it means...
neither am i

and i do know its very very messy and not completely safe....
but it is only my first attempt at OOP stuff....


the code works everytime for me, apart from when my router doesnt respond (a reboot of the router fixed that), but ive never gotten that error....
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

ok, made the code a bit safer, but its just as messy....
(it is only an example)

i reuploaded it as well of course

edit: fixed a little error (after it was uploaded :x )
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

I'm interested in using the upnp interface to open a port for a chat service I'm working on. Currently it fails to run on most routed connections due to the lack of port forwarding; however on most cases upnp is enabled and I'd like to use it.

:lol: should I bash the keyboard and give up?
:?
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

In my experience, using the XP (and vista?) interfaces to control UPnP is a bad idea.
I've had numerous failures - even having to restart the computer (or the router) for it to start working again.

I started working on a native UPnp interface here
Which does only slightly less than this code does. (the other doesn't list mapped ports)

Both codes will probably require a lot of work to convert to PB 4.30
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply