NAT Punch How To?, need help in VB 2005

Started by
10 comments, last by alexus 17 years, 6 months ago
Hi, Ok I searched every where and cant reaaly find the code for nat punch, only the theory! Does any one knows how to do this in VB. net (2005)? im using System.Sockets class Thanks!
Advertisement
You can take any sockets code, such as the code in my article, and translate it to the socket class. It's not really that different from the C version.

I know of no working implementation using Visual Basic, though.
enum Bool { True, False, FileNotFound };
:-(
I dont have C compiler, im running VB Epress Edition

I juess there is no vb implementation because VB socket class returns the port # that is original one and not the one that router assigned :-(

Is it possible to compile your C code to a dll and use it as service file to just get the addresses?

I havent used C since version 4 im even efraid to edit it when I get my compiler installed
Quote:VB socket class returns the port # that is original one and not the one that router assigned


Not true. The library will use the port that is in the packet it receives, when you call something like recvfrom(). However, if your traffic doesn't actually go through the router, then there will be no translation (such as when testing on a local net). Also, some routers will assign the same port as on the inside socket, if that port is available.

Quote:old C compiler


Visual C++ Express Edition is a free download from Microsoft. Make sure you also download and install the Platform SDK to get all the Win32/WinSock programming goodness.
enum Bool { True, False, FileNotFound };
ok yes thats what i assume and the way most packets work that it should have return adress stated rather then general assumed address. But my knowlage of socket calss in VB is like 1% i just found about it last week, and i have no experiance in network programing (thats if we exclude DB apps which are not really network programing)

As to C++ Extress Edition I didntk now it exist, but even if i download it, i will feal like im lost, i havent seen the C code for years...

Oh yea could it be that VB cant read the masked port #?
No, VB is no different from any other language running on the system.

I'm assuming you're talking about VB.NET. If so, it uses the same class that you'd use in C# or C++/CLR. Just read the documentation for the class on MSDN; it's all in there.

System.Net.Sockets.Socket on MSDN.
enum Bool { True, False, FileNotFound };
did read that...
i will post my code when i get to my main pc
ok, i found the error in my code so now i am getting the real remote port BUT when im sending back something to that port i'm getting errro saying host no ready or dosnt accept the the packats.

Why that? Could that be due to TCP or soemthing else?
Ok i did some testings and it dosnt make any sense for me... Here are my observations:

My Setup: Laptop w. IP 192.168.1.197 is behind a NAT device which in not UPnP.
Desctop is not on the nated subnet and is "before" the router, its IP is 192.168.101 and it functions as the server for me to find out the port of laptop to send back the socket in that was that I dont need to configure the routher. Oh router IP 192.168.1.1 (Will consider this as WAN address) Finally defult port for my app is 5124

So...
1) Laptop send to 127.0.0.1:5124 - same app says recived from 127.0.0.1:3315
Sending socket to 127.0.0.1:3315 => Got error no such host or EndPoint not ready

2)Latop sending to Desctop to 192.168.0.101:5124 ... on desctop recived from 192.168.0.100:50710
3) Desktop sending to Laptop on just recived port # to 192.168.0.100:50710 => No host, ok fine
4) Repeating step 3 but with standard port to 192.168.0.100:5124 => No Host

Conclusion: Dosnt work!

What can I do here?
Put my Laptop into DMZ?


You will need to draw a diagram of your network. How come your desktop has 192.x addresses, when you claim it's outside the NAT router, for example? (and you forgot a dot in that address).

What is the external address of the NAT router, btw? Or is what you listed the external address? Then what is the internal address? It would be less confusing if you numbered your external (but still internal?) net using a different number range, like 10.x.

Last: when sending to 127.0.0.1, NAT is not involved. I believe your problem might be that you don't use htons() correctly on the port ID, perhaps?

Example network for testing NAT:

Internet  <-->  20.30.40.50 [NAT Router A] 10.0.0.1                                              |       192.168.0.1 [NAT Router B] 10.0.0.2  <--->  10.0.0.3 [Your Desktop]            |       192.168.0.2 [Your Laptop]


20.30.40.50 is actually your ISP-assigned public IP address.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement