Jump to content

Recommended Posts

Posted (edited)

Thaks for the response, but I already know the dll that the files uses and the functions it calls, i am just not sure how to implement them since it's writen in C. I also tried mimiking the objCreate method but that didn't work eith. But the again, this is my first time with those autoit functions.

Here is what a C code does and what I need autoit to do:

'This program enables an IRC file transfer port

'And then puts up a prompt waiting for the user

'to be finished transferring files

Set theNatter = CreateObject( "HNetCfg.NATUPnP")

Dim mappingPorts

Set mappingPorts = theNatter.StaticPortMappingCollection

'We add a new port saying that externally accept from port 1024

'route to internal port 1024 on computer with IP 192.168.1.101

'Enabling the forward, and giving a name of the forward to be IRC

mappingPorts.Add 1024, "TCP", 1024, "192.168.1.101", TRUE, "IRC"

'

MsgBox("Total number of ports after add is " & mappingPorts.Count & ". Hit OK when you're done transfering")

'To uniquely specify a forward, you give the external port

'and the protocol - here we remove the forward that we added

mappingPorts.Remove 1024, "TCP"

MsgBox("We're done and the total number of ports is " & mappingPorts.Count)

>Anyone know how to do this in Autoit?

Edited by computergeek
Posted

Thaks for the response, but I already know the dll that the files uses and the functions it calls, i am just not sure how to implement them since it's writen in C. I also tried mimiking the objCreate method but that didn't work eith. But the again, this is my first time with those autoit functions.

Here is what a C code does and what I need autoit to do:

'This program enables an IRC file transfer port

'And then puts up a prompt waiting for the user

'to be finished transferring files

Set theNatter = CreateObject( "HNetCfg.NATUPnP")

Dim mappingPorts

Set mappingPorts = theNatter.StaticPortMappingCollection

'We add a new port saying that externally accept from port 1024

'route to internal port 1024 on computer with IP 192.168.1.101

'Enabling the forward, and giving a name of the forward to be IRC

mappingPorts.Add 1024, "TCP", 1024, "192.168.1.101", TRUE, "IRC"

'

MsgBox("Total number of ports after add is " & mappingPorts.Count & ". Hit OK when you're done transfering")

'To uniquely specify a forward, you give the external port

'and the protocol - here we remove the forward that we added

mappingPorts.Remove 1024, "TCP"

MsgBox("We're done and the total number of ports is " & mappingPorts.Count)

>Anyone know how to do this in Autoit?

<{POST_SNAPBACK}>

You sure that code is C? Or maybe I'm misunderstanding you.
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Posted (edited)

mabey c++ sry, i wasn't really paying attention but sometime next week i can look into it, this weekend just wont work out... It was quoted from link abt UPNP earlier in this post. Thanks.

Edited by computergeek
  • 3 weeks later...
Posted

Caution!

I have never used COM, but I've looked at some examples, and this probably isn't even close to working, but it should maybe get you off in the right direction, I wouldn't recomend running it since it doesn't work. Wait for a more experienced person to come along...

;This program enables an IRC file transfer port
;And then puts up a prompt waiting for the user
;to be finished transferring files

$theNatter = ObjCreate( "HNetCfg.NATUPnP")
Dim $mappingPorts
$mappingPorts = $theNatter.StaticPortMappingCollection

;We add a new port saying that externally accept from port 1024
;route to internal port 1024 on computer with IP 192.168.1.101
;Enabling the forward, and giving a name of the forward to be IRC

$mappingPorts.Add 1024, "TCP", 1024, "192.168.1.101", TRUE, "IRC"
MsgBox("Total number of ports after add is " & $mappingPorts.Count & ". Hit OK when you're done transfering")

;To uniquely specify a forward, you give the external port
;and the protocol - here we remove the forward that we added

$mappingPorts.Remove 1024, "TCP"
MsgBox("We're done and the total number of ports is " & $mappingPorts.Count)

:(

FootbaG
  • 2 weeks later...
  • 1 year later...
  • 2 weeks later...
Posted (edited)

AutoIT latest beta: Not working here: :P

C:\Program Files\AutoIt3\uPNPtest.au3(13,19) : ERROR: syntax error

$mappingPorts.Add 1024

~~~~~~~~~~~~~^

Clarification: The original code is Windows Scripting Host code.

This works: :nuke:

;This program enables an IRC file transfer port
;And then puts up a prompt waiting for the user
;to be finished transferring files

$theNatter = ObjCreate( "HNetCfg.NATUPnP")
Dim $mappingPorts
$mappingPorts = $theNatter.StaticPortMappingCollection

If IsObj($mappingPorts) Then
 
 ;We add a new port saying that externally accept from port 1024
 ;route to internal port 1024 on computer with IP 192.168.1.101
 ;Enabling the forward, and giving a name of the forward to be IRC
 
 $mappingPorts.Add (1024, "TCP", 1024, "192.168.1.101", True, "IRC")
 MsgBox(0, "Ports added", "Total number of ports after add is " & $mappingPorts.Count & ". Hit OK when you're done transfering")
 
 ;To uniquely specify a forward, you give the external port
 ;and the protocol - here we remove the forward that we added
 
 $mappingPorts.Remove (1024, "TCP")
 MsgBox(0, "Ports removed", "We're done and the total number of ports is " & $mappingPorts.Count)
 
Else
 
 MsgBox(0, "Problem","Could not create a uPnP object")
 
EndIf

(Note the brackets around the object .add and .remove parameters and the test for the object being created successfully)

In C# the code is as follows:

public void AddPortMapping(PortMappingInfo portMapping) { 
uPnpNat.StaticPortMappingCollection.Add(portMapping.ExternalPort, portMapping.Protocol, portMapping.InternalPort, portMapping.InternalHostName, portMapping.Enabled, portMapping.Description);
}
public void RemovePortMapping(PortMappingInfo portMapping) { 
uPnpNat.StaticPortMappingCollection.Remove(portMapping.ExternalPort, portMapping.Protocol);
}

Hope this documents it a little better.

Edited by Confuzzled

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...