简体   繁体   中英

Port forwarding from C#

I would like to make a program in C# that would port forward a specific port from the router to the computer. Is this possible?

It is possible to forward a port using UPNP (assuming your device supports the technology) using NATUPnP 1.0 Type Library (NATUPNP.DLL) or a third party library like Mono.Nat .

If you want to do it without UPNP then it will be considerably harder since you will need to find what kind of message you will need to send to the device (router) to simulate a user adding a port.

For Mono.Nat you can find an example at UPNP port forwarding – The easy way and for NATUPnP there is an example at .NET Framework: Communicate through NAT Router via UPnP (Universal Plug and Play)

No, it is not possible

Port forwarding is the task of your network device where all the other computers of a network are connected. Once the packet leaves the router, it has no control over it.

Further, unless you forward the port from router, there is no way for a computer in internal lan to get that packet and there is no question of forwarding at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM