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?
-
Unless their router has an API you can use.. you're going in the wrong direction. – Simon Whitehead Nov 22 '12 at 10:05
-
I dont have any information about router. All I know is that ther is ip camera, and I have an app running 24h inside their network, this app should be responsible for forwarding I think – Radosław Malinowski Nov 22 '12 at 10:17
-
Your application cannot have anything to do with port forwarding unless the computer the application is running on is literally the gateway into the network (which it won't be.. that would be a router's job). What you need to do, is have them (or you) forward port 80 externally on the router to port 80 on your camera. This must be done on the gateway. – Simon Whitehead Nov 22 '12 at 10:19
-
This is the only way to get access to ip camera from outside local network? Can my app tell router to forward port? Is it possible? – Radosław Malinowski Nov 22 '12 at 10:22
-
That was what I said originally. It is only possible if the router has an API you can use to make the port forward happen. Otherwise, no. You must logon to the router manually and forward the port. Remember, it only has to do this **ONCE**. Why build something into your program (if it's even possible) if you only have to do it once? – Simon Whitehead Nov 22 '12 at 10:25
-
well, imagine that my client is a 60 years old lady who have no idea what to do. Just plug my box (with win CE) to network and plug camera ip and all is working (local, for now). I can't make her doing some voodoo port forwarding stuff if You know what I mean. And I'm not good in networking so I'm asking. edit: If there would be more than 1 camera she will need to change forwarding every time she would like to see video from different cam :/ – Radosław Malinowski Nov 22 '12 at 10:29
-
Well, I've given you an answer. No, it's not possible through code* * (unless the router has an API.. but that is your job to figure out.. I'm not a mind reader). – Simon Whitehead Nov 22 '12 at 10:31
-
Unless all routers have that api I cant build my app on this solution :/. – Radosław Malinowski Nov 22 '12 at 10:35
-
Hence why websites like http://www.portforward.com exist – Simon Whitehead Nov 22 '12 at 10:35
-
1@SimonWhitehead Such an "API" does exist on most domestic routers - it's called UPnP and it's for exactly this purpose. – tomfanning Nov 22 '12 at 11:09
3 Answers
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.

- 1
- 1

- 9,552
- 4
- 50
- 78
-
UPnP might not be supported by the device, or it could have been disabled by grandma's nephew. – Alex Nov 22 '12 at 11:11
-
Yes, it *may* have, of course. Hence "most home routers in their default configuration". Which, I would guess, is 95% + of domestic routers in the world made in the last 5 years. And if someone makes a decision to disable UPnP, they probably know that they need to forward a port. – tomfanning Nov 22 '12 at 11:14
-
Many routers come with UPnP disabled by default too (I know mine did). I'm not pointing out that it can't be done *period*, I'm saying there's no one-size-fits-all solution for OP's needs. – Alex Nov 22 '12 at 11:28
-
I understand what you are saying, and I'm not being funny but that is EXACTLY what your answer says: *"Only way ... through manual router configuration... There is no way around it"* – tomfanning Nov 22 '12 at 11:44
-
Mine also came with UPnP disabled. I completely disregarded UPnP as an option for the OP..why? I have no idea :/ – Simon Whitehead Nov 22 '12 at 11:48
-
When I turn upnp enable on my router it broke :). I could ping websites but couldnt get them from browser :) also couldnt load routers page in browser, only reset router helped, weird – Radosław Malinowski Nov 22 '12 at 11:55
-
-
My ip camera default port was 80, when I activated upnp on router all incoming traffic on 80 was going to camera :F, this minor problem is solved :) – Radosław Malinowski Nov 22 '12 at 12:48
-
Again, that's not normal. External incoming port 80 being mapped to some internal device should not stop web browser traffic from working. – tomfanning Nov 22 '12 at 13:08
-
Dont know why but it did stop, changed it to 1001 and its working now – Radosław Malinowski Nov 22 '12 at 13:37
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.

- 23,004
- 4
- 39
- 73
-
So "There is no way around it, for logical and obvious security reasons" - apart from *using the accepted standard for doing this task which works in the vast majority of cases* – tomfanning Nov 22 '12 at 11:15
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.

- 149
- 11