Enable port forwarding with c# - 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.

Related

C# TcpListener external IP

I'm creating a TcpListener, and I want clients from other computers to be able to join my listener.
I've read and understood that I have to do Port Forwarding, but it doesn't make any sense to me - when I publish my app, I want other people to create this Listener, and I can't tell them to do Port Forwarding.
Is there any possibility to create a TcpListener that clients will be able to join without Port Forwarding?
Thank you.
Well, lets try to clear somethings out first.
The main reason to use port forwarding is because you have a NAT router in front of an internal network. To setup a port forward is to instruct the NAT router to forward traffic to a certain port on the public interface to a port on an internal computer.
If you don't have a NAT router you don't need port forwarding.
Many routers today support UPnP, a technique to kindly ask the router to create a specific port forward. A suitable library to use might be ManagedUPnP.
However you still need to figure out the public IP of the router and what port you have opened and communicate that to your other applications.
If your router does not allow UPnP or there are other fire wall rules in place you can not set up a port forwarding correctly.
You can create server application and forward ports on your pc. Client application (this one you will publish) will just connect to your pc so they can be on the NAT. You can also combine your application with some php/asp pages but it depends on data you would like to send. If it's some kind of PC statistics like uptime, hardware etc. you would just use http query in client app to website script you've created (for instance mypage.com/?uptime=100&ram=2gb&hash=xxxx etc.)
Only the server (the computer which is accepting TCP requests) needs to have the port forwarded.
The common model is that you (the developer/producer of the service) host the server. Then customers (people who subscribe to your service) connect to your service using either an IP or a URL. If your service is behind a firewall (you have a router between your computer and your internet modem) then you will have to forward the port. You will probably also have to open the port in Window's firewall, but I expect you have done this already. In this model the customer does not have to do anything with their router (it is like using a web browser).
If you are making a product where your customers are hosting the service then they will have to deal with the port issues. In which case you could try ManagedUPnP like Albin Sunnanbo suggests or redirect them to one of the many sites explaining how to setup port forwarding.

Hosting a game on a PC - UDP or UPNP communication?

I've built a server-application for a game that I want general people to use. Now, since I've worked with client/server solutions before, I know how tedious it is to host connections on some computers.
So, I heard about these rumors that I would like to get confirmed.
Using UDP for "hosting" a connection is good, because it is rarely blocked by router-firewalls compared to TCP.
Using UPNP for communicating with a router is good, because it allows you to add port forwarding for the game, making your server reachable no matter if you're using TCP or UDP.
I don't care about the software-firewall people may use. What I care about is the router firewall functionality.
Any help would be appreciated.
Thanks!
For your two rumors,
I don't know, I have not worked with firewalls enough, but I would not call that one true. Most routers block everything (TCP and UDP) unless you explicitly ask it to forward it for inbound connections via hand setup or UPNP. If you don't tell the router what computer wants info coming in to port 12345 how will it know what to do when a user sends a unsolicited packet to it (the definition of being a server).
Yes, learning how to do UPNP will make it a lot easier for your users to host games, however you should still provide instructions for people who do not have UPNP turned on or their router does not support it.
The other thing you may want to look in to is learning how to add your program to the windows firewall client allowed list as that is what most of your users will have. See this SO question for more details.

How do I make my ASP.Net website viewable in my private home network using IIS 6.0?

I want to know how I can make website available in my private home network? I know I am supposed to make my IP address static but I still do not know the complete steps to accomplish what I want to do. Is this even possible? If it is can someone please explain to me what I have to do?
A lot of ISP's won't allow you to receive requests on port 80. However, you can test this by trying...
-Install IIS - when you go to http://localhost, you should see an IIS start page.
-If you have a router/switch, you'll need to access the admin interface on it. This is usually default 192.168.1.1, but varies by manufacturer. You'll also need to get the local IP address of your IIS server. Go to run, hit CMD, and type IPCONFIG.
-Inside the admin interface, you'll have port forwarding. Forward port 80 to the IP address of your IIS server. Save.
-Now, get your actual IP address by going to a site like whatsmyip.com.
That should do it. Ask a friend or a family member to browse to your IP address. If they see your site, your ISP allows you to host. If they don't see it, your ISP has it blocked..
Having said that, you should check out serverfault.com - this question is more suited for that site.
This is pretty easy but you need to read up on some security before making anything live.
Static IP addresses cost more money than dynamic ones so I suggest signing up to http://www.no-ip.com/. It's requires installing a program which updates a domain which your ip address everytime it changes.
You will also need to use port forwarding on your router so it knows to send all http requests to your PC. HTTP data to passed normally through port 80 or 8080.
Hope this helps.
Check this out: http://msdn.microsoft.com/en-US/library/1y1404zt(v=VS.90).aspx

Monitor Internet Connection using C#

I want to monitor my router to see what is currently being downloaded and what application/Software that initiate it, who is the user doing this and download speedthat user occupy
i got all credential needed for both my wireless connection and the router
any head start for sth like that in C#?
the idea
First of all: Do you even know that your router can do this? Most routers I've seen do not have this level of traffic understanding and management.
If your router does, then there is one of two ways that such data is generally made available:
1) Through a HTTP interface (password protected)
or
2) Through an SNMP interface
To retrieve the appropriate HTTP URL, you simply get it as you would any other web page. Try something like: http://www.csharp-station.com/HowTo/HttpWebFetch.aspx
To retrieve the SNMP settings, there are many options; try this question: What SNMP library for .NET makes traps, sets or gets simple?
However, most likely, your router will not actually have this information available.
So, edit: If your router doesn't support side-chaining, and doesn't support SNMP or similar statistics, then you can't do this in the general sense.
You could spin up a Linux box as the gateway for the machines, and use NAT session statistics to monitor this. The way to do this is to have two network interfaces (logical or physical), one of which gets an IP from your modem, and the other which is the default gateway for the wireless network. Turn on IP forwarding and masquerading (NAT) as well as a DHCP server for the wireless network side. Now, you can use iptables to look at active NAT sessions and how much data has been transferred. You can also use packet filters for more specific information.
Also, if you know which machine is doing the downloading, and are running Windows, you can use WMI ("perfmon.exe" to plot this) to see how much data is being transfered on the actual machine.

C#, socket through router

I made a remote engine for a game which must be able to works in P2P.
It perfectly works in LAN, but there's a problem when computers are behind router(s) and want to communicate through internet.
Is there any solution to this, which doesn't need to manipulate the router configuration?
Because since most of my gamers may not be very acknowledged in informatic, I'd like to solve this problem as easily as possible, without any intervention from them.
Thanks,
KiTe.
You need the client behind the router to initiate an OUTGOING connection. Once that's established you can have 2 way communication on it. This is why most P2P games have some sort of server to set up matches between clients. You can have each client establish a socket to the server and then connect them to each other.
There was an alternative called 'NAT hole punching' a while back, but I'm not sure how reliable that was.
This is what separates LogMeIn from VNC.
These days almost all home users are behind a form of NAT, macking it impossible in practice to set up real peer-to-peer communication as the application listenning port is unreachable from the net.
In theory there is UPnP which allows applications( running under elevated priviledges) to enable port forwarding dynamically on the home router (via Internet Gateway Device Protocol), but in practice this is so unreliable that I haven't seen any real use of it.
The most reliable solution is to have a central hub (your game server) that forwards packets between clients that initiate the connection from behind the NAT device. But that is a serious cost to you, as you'll need to cash out the cost of provisioning and operating this hubs which can be serious money, even with dynamic just-in-time solutions like EC2.
Update
Perhaps you can use the Codeplex UPnP NAT traveral project.

Categories