Flaccid_Jack Posted October 6, 2020 Posted October 6, 2020 (edited) Trying to use j0kky's STUN UDF to identify the external port for TCP connection between two non-server computers. From what I understand, I'm supposed to use the local port that I'm testing as the parameter for the function "_STUN()". In the UDF comments, j0KKy writes the result should be a two-element array: "|[0] - The external IP address |[1] - The external port" My problem (I think it's a problem) is the function keeps returning the same number as I used in the parameter! $result[1] in the below script will always come back as 52345.. $iLocalPort = 52345 $result = _STUN(iLocalPort) If @error Then ConsoleWrite(@error & @CRLF) Else ConsoleWrite($result[0] & " : " & $result[1] & @CRLF) EndIf Am I missing something? I can't find any examples or help threads regarding STUN.. edit:typos Edited October 6, 2020 by Flaccid_Jack
JockoDundee Posted October 6, 2020 Posted October 6, 2020 It might do that! And it might be correct. Your router is like anybody else, they like to do as little work as possible, so many routers will not change the port if they don’t have to. To test this, use two computers using the same source port at the same time. This will make the router come up with a new port number for at least one of them. also, if you have a cell phone that u can connect to as a hotspot via WiFi (instead of your router), those port numbers almost certainly will be distinct. Code hard, but don’t hard code...
mLipok Posted October 6, 2020 Posted October 6, 2020 On 10/6/2020 at 3:18 PM, Flaccid_Jack said: Trying to use j0kky's STUN UDF Expand Please post link... as I and many other forum members often are lazy, or overworked, and do not want to waste xyz time to search something you know where is it. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Reveal hidden contents Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
water Posted October 6, 2020 Posted October 6, 2020 (edited) Took me 3 seconds: https://www.autoitscript.com/forum/index.php?showtopic=185329 by searching the wiki Edited October 6, 2020 by water My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Flaccid_Jack Posted October 6, 2020 Author Posted October 6, 2020 (edited) So here's what I'm trying to do: I want to use TCP to connect two computers hidden behind NAT (without forwarding ports). I think that is the purpose of STUN. I tried using the result I got from the _STUN function, but with no luck. However, I am very foggy in my understanding, but I think it's possible both computers have to be connected to the STUN server at the same time so the server can link them together? Or maybe that is just another way of using STUN? Here is my code: Host: Local $sIPAddress = @IPAddress1 Local $iPort = 12345 ; Port used for the connection. $iListenSocket = TCPListen($sIPAddress, $iPort, 100) Client: Local $sIPAddress = "23.200.110.26" Local $iPort = 12345 ; Port used for the connection. Local $iSocket = TCPConnect($sIPAddress, $iPort) Edit: changed IP address Edited October 6, 2020 by Flaccid_Jack changed IP address
JockoDundee Posted October 6, 2020 Posted October 6, 2020 On 10/6/2020 at 6:46 PM, Flaccid_Jack said: However, I am very foggy in my understanding, Expand Flaccid, the STUN UDF is NOT an end to end P2P networking solution. It IS, imo, a significant piece of the puzzle. There is no hooking together of the ends by STUN, that is up to you. All STUN tells you is your external IP and your external Port for a given outbound connection. just like your machine IP address is a local one, 192.168.x.x perhaps, your source port is also local. Your router always changes your IP to your public one and often changes your port as well. Without STUN you don’t know what they have been changed to. This is key information, because if you can communicate it to the other endpoint, you have a good chance that you can fool the other router into thinking that that side initiated the connection, and it will let the traffic flow. Honestly, it’s fairly complicated, if I were you I would really want to understand NAT and P2P pretty well before attempting the whole shebang. Maybe somebody has a working UDF with everything in it, I don’t know. btw, if you can’t use udp, instead of tcp, your success rate drops in half. https://en.wikipedia.org/wiki/STUN Code hard, but don’t hard code...
Flaccid_Jack Posted October 7, 2020 Author Posted October 7, 2020 Thanks @JockoDundee. I appreciate you taking the time to help me out. Perhaps I will pursue other avenues, this seems to be a bit beyond my capabilities, at least for now
JockoDundee Posted October 7, 2020 Posted October 7, 2020 On 10/7/2020 at 2:14 AM, Flaccid_Jack said: Perhaps I will pursue other avenues, this seems to be a bit beyond my capabilities, at least for now Expand well probably not beyond, it’s definitely learnable, but without understanding the concepts about it, and when it may work and what to do when it doesn’t, it could be frustrating at times. one important question: do you have a way for the two endpoints to communicate their public ip and ports to each other? For instance, teamviewer has their own servers which handle the exchange. but it doesn’t have to be a server per se, heck, you could even do it with email, if you don’t mind a few seconds of lag time. maybe somebody has a stun server/state saving public matchmaking server that could do it all. btw, I started with the STUN udf, but once I realized that I still need a way to communicate between the two, I just got a domain from bluehost for $4\month, wrote my own stunnish server with matchmaking in php, and the client using winsock udf (not the built in sock stuff because it doesn’t let you set source port). If you go that route let me know, you’re more than welcome to my php code Good luck! Flaccid_Jack and BugSteve 2 Code hard, but don’t hard code...
Flaccid_Jack Posted October 7, 2020 Author Posted October 7, 2020 (edited) Well, I admit I was kind of ducking out of the conversation because I felt like I'd probably taken enough of your time (though that's obviously your decision not mine), but I do still have questions that my reading hasn't solved for me. I'll start with my confusion regarding ports. 1) I read that different applications have different ports; email uses 25, web browsers use 80, etc.. When a router receives traffic, if it's using the port number to determine which app to use, then how does it know which network device to send the data to? 2) When a network device starts up and connects to the router, does it get assigned a specific port for that session? I am wondering how the _STUN function even works, or rather, what the result actually means. If it's returning my external port based on the internal port that I set as the parameter, does that mean the network has assigned my computer an external value for every port? So, like in my question above; maybe an email comes in for my external port number, which is unique, but then sends it to my computer's local port 25? Thanks again, I know your time is valuable. Edited October 13, 2020 by Flaccid_Jack
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