Jump to content

Recommended Posts

Posted (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 by Flaccid_Jack
Posted

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...

Posted
  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 Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Took me 3 seconds: https://www.autoitscript.com/forum/index.php?showtopic=185329 by searching the wiki ;)

Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (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 by Flaccid_Jack
changed IP address
Posted
  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...

Posted
  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!

 

Code hard, but don’t hard code...

Posted (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 by Flaccid_Jack

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...