I've searched this subject in stackoverflow and found out that a telnet library would help, and I found a telnet lib here: C# Telnet Library but I don't know how I can use a telnet library to open a port in my router. I'm using an AT&T 2wire router. Any hints on how I can do this?
2 Answers
You can't. The 2wire router is an island unto itself, if it decides to block a port nothing external can (or should) be able to change that. You are on the wrong track, and would need to restate your goals in order to get a useful answer.
UPnP and other "Hole Punching" techniques do exist: but you'll be in a world of hurt if you try to reply on them for any widespread deployment.
Perhaps you meant to open a connection to a remote server and then establish two way communication. That is easy... and how other games and tools get the job done.

- 8,313
- 6
- 55
- 73
-
Thanks, but I'm doing socket programming and if I don't open the port through which my program communicates, I can't publish my application. I can do it for my own device, but the user who is going to use this program should not have to go through all of that trouble. – dsynkd Jan 09 '12 at 00:17
-
Universal Plug and Play http://en.wikipedia.org/wiki/Universal_Plug_and_Play attempts to solve what you describe... but brings with it a huge variety of other problems. – Bryce Jan 09 '12 at 19:36
-
Do all of the applications that do networking use this Universal Plug & Play? – dsynkd Jan 10 '12 at 17:19
-
Because networking would be meaningless if the ports through which you're going to communicate are always closed – dsynkd Jan 10 '12 at 17:20
-
The answer I gave is correct. What you need to do is go find some basic socket or internet example programs online and get them working... learn enough about the subject to formulate a good question. Common consumer routers don't block ports the way you describe. You were downvoted last time you asked this same question: please do research before asking again. – Bryce Jan 18 '12 at 05:29
-
I'm voting this question down: you need to do more research on your own, and read the helpful advice several people have given you. – Bryce Jan 22 '12 at 20:27
Technically speaking you should not be able to. You shouldn't have outside programatic access to a router to open a port if it's blocked.
If what you mean is opening a port for communication (that is not blocked) then you can simply create Sockets with the address and port (ex. localhost 7777) to establish inter process communication or simply communication with another server.
As I mentioned in a comment below there are ports that are available for use (in C# this can be easily tested, a quick google search will find you many snippets of code for testing if a port is open). A simple approach is to simply start at port 1024 (I believe this is the correct lower bound for ports that should be used by applications, someone correct me if I'm wrong) and just start counting up until you find a port that is available, if you find you've reached some upper limit you can simply report that a connection cannot be made. I hope this clears up a little more and if I have time I will try to find some code I have for this and edit it in but honestly a quick search can net you similar code for checking ports in C#.

- 22,940
- 10
- 58
- 88
-
Well, that's exactly what I'm doing: I'm trying to write some sockets and make them communicate. But they can't do so since the port through which they are going to communicate is closed. I wonder how some games and applications are able to do this, and I wanted to use the same method – dsynkd Jan 09 '12 at 00:15
-
They use common ports that aren't closed such as port 80 (and a couple of others I can't remember). Or instead they don't use communication via ports and send messages to servers through other wrappers. – Jesus Ramos Jan 09 '12 at 00:36
-
Isnt port 80 already asssigned to http protocol? Also, when I type in netstat -n in command prompt I see a bunch of programs connected through other ports, which are supposed to be closed. – dsynkd Jan 09 '12 at 17:29
-
Yes I'm just trying to make a point that they are open by default (although some may be reserved). Port Forwarding is really a requirement unless you plan on using something like Hamachi as a mediator for your application. – Jesus Ramos Jan 10 '12 at 06:18
-
Thanks. I also wanted to know: How do other applications, like skype, GTalk, Yahoo Messenger, etc open the port they need? – dsynkd Jan 10 '12 at 17:19
-
There are ports above 1024 (I believe this is the correct number) that are automatically open for use. I can't really remember which though as I haven't really done much networking and client/server stuff in recent years so I've forgotten. – Jesus Ramos Jan 11 '12 at 01:43
-
1@V0R73X - you are do not appear to be listening very carefully. You are approaching the problem incorrectly, that's why you're having trouble. – Bryce Jan 11 '12 at 07:02