开发者

Check if client port is open and forwarded [C#, ASP.NET]

What is the best way to check if client has an open port, and if it's forwarded properly?

The app works like this currently:

  1. Client creates a socket for incoming connections and wants to notify everyone about his open port. Client also tries to setup port forwarding using UPnP (but it's not always present and enabled).
  2. Client then sends his port to the "central" known server.
  3. Server should check if the port 开发者_StackOverflow社区is open (forwarded properly) and return its status.
  4. If there is a forwarding problem, client will notify user.

The goal is to have an the IP + port info saved on the server to be able to give it to other clients. I could try to open a Socket from server to client and see if it fails, but is there an easier (faster) way to do it?

For example, this site does something like that: http://www.canyouseeme.org/


No, there isn't.
To check if a connection can be established, you need to try to establish a connection :) Using a Socket is a sensible way of doing just that.

You could possibly skip this step for some clients, by checking if the machine has a public IP address or a local one. Still, there is the possibility of company firewalls and things like that, so trying to open a connection is the safest way to go.

Using an ICMP echo request (ping) is not an option, because ICMP is a different protocol from TCP (or UDP) that has no concept of a port number. Pinging can be used to determine if an IP address is reachable, but this is of no added value to your case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜