MSTSC.exe with STUN - c#

Is it possible to connect mstsc.exe of one PC of one maching behing NAT to another machine behing NAT via STUN / hole punching.
If yes, could you please help how it can be done in c#.
As i understand there're lots of public stun servers over internet and the idea is to get some sorts of public address and then pass it as command line argument to mstsc ?
Thanks

Actually seems this problem - unability to access one PC behind NAT from other PC behind NAT is solved by Microsoft in 2009 (!).
It is possible to set a secure IPv6 name for a computer behind NAT and use it for remote desktop connection from outside PC because there's no need to come via nat for IPv6.
https://learn.microsoft.com/en-us/previous-versions//bb727045(v=technet.10)

Related

How to connect my .net application to SQL Server via internet

I have created a C# application with a login form (I use SQL Server database and SSMS). The database is on my PC, when I run the program on another PC which is in the same network as mine, everything works fine, but when I connect one of the laptops on another network, an error occurs: "The path wasn't found".
Is it possible to connect with the server remotely, via internet or something,
without having to be on the same network?
I already have:
Opened tcp and udp ports
Allowed SQL Server ports in Windows Firewall
Added an inbound rule for tcp (port 1433) and udp (port 1434)
Allowed remote connections
Here is my connection string:
Data Source=<server name>;Initial Catalog=Name;User ID=Minko;Password=Password1
This is not a programming question, but a Networking one.
To have a server reachable in the internet, is a costly mater. The static IP adress alone will cost a pretty penny, never mind actuall hardware.
On a small/no budget, VPN is perhaps the only way. Via VPN you can connect two local Networks (the home side of the Routers), allowing devices to talk as if they were physically in the same network.
No change to the programm is nessesary. If it works local, it works over VPN. The network classes do not care if the target is on the same computer, the same Switch or the Voyager probes.
The user will have to connect to teh VPN endpoint you have to provide - and usually can provide for cheap with any decent Router.
First off you should definitely change that PW.
Also - you make the comment that you are trying to use the same program to connect from a different network - implying that you haven't changed the IP address...
Are you sure you're using your public IP address? (Not your local network one that will start with 10. / 172. / 192.
Make sure you're using your public IP address... if you do this even if you're on the same network it will treat it as if you're not. It seems to me like you're still trying to use the local network's IP.
If it persists make sure you can reach the PC itself: ping ip-of-host in Powershell.
Connecting C# with SQL Server Database in a Local Area Network (LAN)
Try these steps one by one :
1- Find your public IP address using ( www.whatismyip.com ) for example.
2- Check that you can connect to the database using the public IP. To do that go to SSMS, and in the server name try to use IP-address only, or "IP-address\[instance-name]. If doesn't work, then you have to fix this first. Check this: https://dba.stackexchange.com/questions/62165/i-cant-connect-to-my-servers-sql-database-via-an-ip-address
3- When step 2 works, then you can use the "IP-Address\[instance-name]" in the connection string.

Host server on Raspberry

Ive made a simple chat Program in c#. It uses tcp. I can start the server and clients can connect and chat if everyone is in the same network.
I now want to put the server on my raspberry pi which has raspbian installed.
So far so good it works and i can connect again if everyone is in the same network, but now i want to access the server over the internet as a private person cant geht their hands on an public static ip adress, ive read that i could use ddns.
I have a host name on no-ip and installed noip2 on the raspberry and followed the instructions.
On their site they write you can test it with the command sudo noip2 -S. It shows that it connected with my account and will update my hostname.
In theory everything should be working, but i cannot connect to the server neither to the raspberry.
Anyone of you knows what i can do to make it work or is it the completely wrong way?
Thanks in advance!
You could use dyndns together with cname.
You would need to open port 80, 443 on your router.
This implies risk for the other devices in your network.
Instead of using rpi locally you could get a small virtual hosting server at AWS/Google for around 3$ per month.
Simply put, if you don't have a public IP, there's no way to connect to your RPi. If the IP address starts with 192.168, 172.16 through 32 or 10. then it's by convention (or definition depending on how you look at it) a non-routable address which means you can't get to it over the Internet.
DDNS is just a way of translating from a name to an IP address and doesn't imply anything about being accessible to the public. Noip is just a way of being able to associate a name with a dynamic IP address, which again does not imply anything about being accessible to the public. In other words, if www.yourdomain.com resolves to 192.168.1.2 (for example), it doesn't matter who can resolve the name, they still can't get to your server.
If your router has a public IP (which you said it doesn't) then you would be able to do a NAT translation, but based on what you said, that's not possible either.

Enable port forwarding with c#

I use a basic application that enables me to send a file over a tcp connection over the internet to a different computer. The way I managed to do that was to configure the router at my house and office to port forward all incoming traffic from port X to the corresponding computer. I am in a new office now and things work different in here.
There is a main router where all the offices may connect to. I connect my router to that router in order to have my own private network. I still want to be able to use my small application that I created in order to sync the files from my home computer and office computer. The only problem is that I dont have access to the main router therefore I may not open any ports in order to make my program work. I am new to networking so it will be nice if someone can point me to the right direction of how can I solve this. I think I have to let the router know to send all the traffic from port x to my computer. Moreover there are several routers so I dont know if it is possible. I think it should be possible because I am able to connect to my office computer via log me in for example.
It sill be nice if I can still use TCP protocols instead of a p2p since I already have all the functionality.
It would be much easier to connect from your office to your home computer. In this scenario, you have to setup port forwarding on your personal router (which you have already done!). If you connect from your home to the office, you will need to configure every intermediate office router (which your boss probably won't like).
In order to connect to your home network, I would look into setting up DDNS through someone like DynDNS. This will allow you to connect to me.example.com from wherever and have it resolve to your home address even when it changes IP addresses.
I found a nice page that talks about this in here. I will work on it... I am not sure if it works with the tcp protocol.

Testing a Remote Client-Server Application

Yesterday, I posted a question on some tips doing this Remote Client-Server Application in C#. So now, our group was able to create one. The problem is, we cannot think of ways on how we can test it since we are currently on different locations for our weekend break.
If anyone of you has any idea on how we can test it, please give us some hints.
Since you have both client and server programs, you can simply run them both on same PC and test them just like they would be on different machines. (use "localhost" or "127.0.0.1" as IP address of server)
It's enough to test program algorithm, and once it work on same PC, it should actually work on any two machines over internet/LAN.
Of course you should understand how networking actually works. Whoever you are connecting, must be visible to you. If you are going to connect via internet, server's IP address might not be enough. Something like http://www.showmyipaddress.com/ might show ISP's front, "white" address. And user, who run the server might have "grey" IP address, behind a NAT. So if you are going to use something like showmyipaddress.com , check your real IP address by typing "ipconfig -all" in windows command line. If ipconfig shows same IP, there are high chances it will work over internet (just check your firewall).
Have one of you setup the server, the other the client. Make sure your configurations match (use the server IP address, as you will probably not have a server name that can resolve via DNS).
Browse to http://www.showmyipaddress.com
Your ip address is listed there
Tell your ipaddress to the others (You need to open a port in your FW/router if you have one)
Tell them to change localhost to your ipaddress in the application and then connect.
you can use VMWare and run virtual machine (it's your choice), and run the server and the client in the same machine.
or you can run it on the same machine, just run : "ipconfig" on the command prompt ! get the IP and use it, or in some languages you can use the keyword "localhost", good luck

tcp streams problem c#

When i try to connnect to a local IP everything goes wonderfully
but as soon as i use a normal ip, like to connect to a friend of mine outside the lan it just doesn't work
It's most likely a combination of firewall and port forwarding. In addition to opening up ports on your firewall, you'll need to forward these ports on your friend's router. PortForward.com is a decent resource if you're unfamiliar with port forwarding.
My first guess would be that you may be running into a firewall issue - is there a firewall operating between you and your friend? If so, do you have exceptions for it?
I suggest you use Wireshark to analyse what's happening at the network level.

Categories