PhoenixXL Posted September 9, 2012 Share Posted September 9, 2012 (edited) Hello Every OneI tried many of the TCP Chat programs which worked flawlessly between my computer and my moms computer in the same WiFi NetworkThen I decided to give the program to my friends and do chat with themBut, that didnt workAfter a lot of searching I found that PORT FORWARDING would be required for Private networksMy friends were not aware of any of this, therefore i chose to make a program that could do the PORT FORWARDING by itself.I finally chose the NAT-PMP for this,But I'm not able to find anything to do it.Please Guide my in the Right DirectionThanks for your Time Edited September 9, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
stormbreaker Posted September 9, 2012 Share Posted September 9, 2012 I always prefer UPnP. See http://www.codeproject.com/Articles/27237/Easy-Port-Forwarding-and-Managing-Router-with-UPnP. A good place where I got started... ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
PhoenixXL Posted September 9, 2012 Author Share Posted September 9, 2012 Thanks. Topic Solved My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
nullschritt Posted September 10, 2012 Share Posted September 10, 2012 Could you please share you solution on how to automatically portforward with UPnP? Thanks. Link to comment Share on other sites More sharing options...
guinness Posted September 10, 2012 Share Posted September 10, 2012 Why not use the UDP protocol? Since from your initial post both your Mum and you are on the same local area network. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
PhoenixXL Posted September 10, 2012 Author Share Posted September 10, 2012 (edited) nullschritt, this code worked for me I got it from the Forum and modified it as per my needs expandcollapse popup;Port Forwarding Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling. $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler Global $debuglog = "Chat Debug.log" Global $debug = 0 ; 1 = Log , 0 = no log Global $console = 0 ;1=ConsoleWrite , 0= No ConsoleWrite If is_privateIP(@IPAddress1) Then PortForward('TCP') If @error Then Exit -1 Func PortForward($nProtocol='UDP',$nInternalPort=6800,$nExternalPort=$nInternalPort,$nIPAddress=@IPAddress1,$nDescription='PortForward') If FindDevice() Then Return SetError(0,0,UpnpPortMap($nIPAddress, $nInternalPort, $nExternalPort, $nProtocol, $nDescription)) EndIf Return SetError(1,0,0) EndFunc Func UpnpPortMap($InternalIP, $InternalPort, $ExternalPort, $Protocol, $Description) Local $theNatter = ObjCreate("HNetCfg.NATUPnP") If IsObj($theNatter) Then DebugMsg("HNetCfg.NATUPnP.StaticPortMappingCollection now") Local $mappingPorts = $theNatter.StaticPortMappingCollection DebugMsg("HNetCfg.NATUPnP.StaticPortMappingCollection.Add now") $mappingPorts.Add($InternalPort, $Protocol, $ExternalPort, @IPAddress1, 1, $Description) ; at this point we know that we have IGD device and we was unable to open port via HNetCfg.NATUPnP StaticPortMappingCollection.Add ; so lets try with MiniUPnP Project link to site http://miniupnp.free.fr/ ; many distribution use this project If $g_eventerror = 1 Then If miniupnpcaddstatic($InternalIP, $InternalPort, $ExternalPort, $Protocol) Then DebugMsg("ok port is open on router") Return 1 EndIf Else DebugMsg("ok port is open on router") Return 1 EndIf EndIf DebugMsg("fail to open on router") Return 0 EndFunc ;==>UpnpPortMap ; this is taken from forum :) Func FindDevice() Dim $deviceFinder Dim $DeviceType Dim $Devices Dim $Device Dim $strDescDocURL $deviceFinder = ObjCreate("UPnP.UPnPDeviceFinder") $DeviceServices = ObjCreate("UPnP.UPnPServices") $DeviceService = ObjCreate("UPnP.UPnPService") $Device = ObjCreate("UPnP.UPnPDevice") ; we need any version of IGD device curently there only 1 and 2 :) $DeviceType = "upnp:rootdevice" $Devices = $deviceFinder.FindByType($DeviceType, 0) DebugMsg('strDescDocURL:' & $strDescDocURL) DebugMsg("Found # :" & $Devices.Count & " Devices") If $Devices.Count = 0 Then DebugMsg("Unable to find Device.") EndIf For $DeviceObj In $Devices $deiceDescription = "Children " & $DeviceObj.Children & @CRLF & "Description " & $DeviceObj.Description & @CRLF & "FriendlyName " & $DeviceObj.FriendlyName & @CRLF & "HasChildren " & $DeviceObj.HasChildren & @CRLF & "IsRootDevice " & $DeviceObj.IsRootDevice & @CRLF & "ManufacturerName " & $DeviceObj.ManufacturerName & @CRLF & "ManufacturerURL " & $DeviceObj.ManufacturerURL & @CRLF & "ModelName " & $DeviceObj.ModelName & @CRLF & "ModelNumber " & $DeviceObj.ModelNumber & @CRLF & "ModelURL " & $DeviceObj.ModelURL & @CRLF & "ParentDevice " & $DeviceObj.ParentDevice & @CRLF & "PresentationURL " & $DeviceObj.PresentationURL & @CRLF & "RootDevice " & $DeviceObj.RootDevice & @CRLF & "SerialNumber " & $DeviceObj.SerialNumber & @CRLF & "Services " & $DeviceObj.Services & @CRLF & "Device URN Type " & $DeviceObj.Type & @CRLF & "UniqueDeviceName " & $DeviceObj.UniqueDeviceName & @CRLF & "Product Code - UPC " & $DeviceObj.UPC & @CRLF DebugMsg("Found The Following Device(s)" & @CRLF & $deiceDescription) Next If $Devices.Count > 0 Then Return 1 Return 0 EndFunc ;==>FindDevice Func miniupnpcaddstatic($InternalIP, $InternalPort, $ExternalPort, $Protocol) Local $ResultMiniUpnp = Run(@ComSpec & " /c " & ' upnpc-static.exe -a ' & $InternalIP & " " & $InternalPort & " " & $ExternalPort & " " & $Protocol, @ScriptDir, @SW_HIDE, 0x2 + 0x4) Local $upnpc_static_output While 1 ; read output from cmd command $upnpc_static_output = StdoutRead($ResultMiniUpnp) ;exit on error If @error Then ExitLoop ; send output to window If $upnpc_static_output Then DebugMsg($upnpc_static_output) WEnd EndFunc ;==>miniupnpcaddstatic ; This is my custom error handler ; we don't want script to fail if HNetCfg.NATUPnP fails Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) If @error Then Return Local $msg = "!> COM Error with HNetCfg.NATUPnP!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext DebugMsg($msg) $g_eventerror = 1 ; something to check for when this function returns Return EndFunc ;==>MyErrFunc Func DebugMsg($debugtext) If $debug Then Local $file = FileOpen(@ScriptDir & "" & $debuglog, 1) If $file = -1 Then MsgBox(0, "Error", "Unable to open file." & $debuglog) Return 0 EndIf FileWriteLine($file, @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & "->" & $debugtext) FileClose($file) If $console Then ConsoleWrite($debugtext & @CR) EndIf Return 1 EndFunc ;==>DebugMsg ; #FUNCTION# ==================================================================================================================== ; Name ..........: is_privateIP ; Description ...: Get if the IP is Private ; Syntax ........: is_privateIP($nIp) ; Parameters ....: $nIp - The IP to be checked ; Return values .: 1 - IP is Private ; 2 - IP is Public ; Author ........: Phoenix XL ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func is_privateIP($nIp) Local $pri_addrs[5] = [ _ '10.0.0.0|10.255.255.255', _ '172.16.0.0|172.31.255.255', _ '192.168.0.0|192.168.255.255', _ '169.254.0.0|169.254.255.255', _ '127.0.0.0|127.255.255.255' _ ]; Local $aAssign, $start, $end Local $long_ip = ip2long($nIp) If $long_ip = -1 Then Return SetError(1, 0, -1) For $pri_addr In $pri_addrs $aAssign = StringSplit($pri_addr, '|', 2); $start = ip2long($aAssign[0]) $end = ip2long($aAssign[1]) ; IF IS PRIVATE If $long_ip >= $start And $long_ip <= $end Then Return True Next Return False; EndFunc ;==>is_privateIP ; #FUNCTION# ==================================================================================================================== ; Name ..........: ip2long ; Description ...: Convert the IPv4 into Long ; Syntax ........: is_privateIP($nIp) ; Parameters ....: $nIp - The IP to be checked ; Return values .: ; Author ........: Ptrex ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func ip2long($nIp) $split = StringSplit($nIp, '.') If $split < 4 Then Return -1 $long = ($split[1] * 16777216) + ($split[2] * 65536) + ($split[3] * 256) + ($split[4] * 1) Return $long EndFunc ;==>ip2longTell me if the code works for you too Guinness, Then I decided to give the program to my friends and do chat with them But, that didnt workThis is the reason for port forwarding Edited September 11, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
guinness Posted September 10, 2012 Share Posted September 10, 2012 Ah, sorry PhoenixXL missed that point. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now