port forwarding camera ip c# - c#

I'm not good in networking so for some people my question can look silly. I'm trying to connect to my ip camera from outside of my local network. I know that I need to do port forwarding. I read that ssh could be good idea. Imagine that my outside ip is 10.20.30.40 and my camera ip local ip is 1.2.3.4. When port forwarding will work I think that I will connect to camera using this address
"http://10.20.30.40/index1.htm". So all I need is port forwarding. Client can't do this on his own. I need to write an app to do this automatically. How can I do this using c# and am I going in right direction?

You can accomplish this on most home routers in their default configuration using UPnP - Universal Plug and Play.
This is a standardised mechanism for applications behind a NAT router to programmatically request ports to be forwarded to them.
See this question for details on accessing UPnP functionality from .NET. You need to persuade the router to forward TCP port 80 (standard port for HTTP) to your camera's LAN IP address.

Only way you can accomplish correctly configured port forwarding is through manual router configuration.
There is no way around it, for logical and obvious security reasons.

Ok, problem solved, when I turn upnp on my router on web pages didnt load. It turns out that camera had default port set to 80. I've changed it to 1001 and then set upnp enable on router and camera automatically forwarded port 1001 to it self. All I have to do programaticaly is set port on camera.

Related

Force NAT UPNP port forwarding

I would like to forward ports automatically with my application, however UPNP is off by default, but Spotify was able to forward ports when even UPNP is disabled, same applies to uTorrent and others.
How do I force port forwarding, or Enable UPNP on rounter, forward port and disable it again?
Maybe these services use UDP hole punching.
See: Wikipedia article

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.

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.

client server app upnp / port forward question

I am thinking about writing a client server app using sockets in c#. My question is, if the server is behind a router and upnp is enabled, once the server starts listening does upnp automatically forward data incoming to that computer if it is destined for said port? I don't want the user to have to start forwarding ports, I am hoping my server app can be zero configuration.
Thanks in advance.
I worked on a uPNP tool a little while ago for a work application for file sharing across multiple sites.
I can confirm that during the port configuration via uPNP, that you do indeed specify which port and end point you would like to listen.
If uPNP reports back OK. All requests to the port will be forwarded to the passed end point.
I will find the class I made \ modified and give it as an example shortly....

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