Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Port Forward w/ Open.NAT #21

Open
Deathreus opened this issue Mar 26, 2020 · 2 comments
Open

Automatic Port Forward w/ Open.NAT #21

Deathreus opened this issue Mar 26, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@Deathreus
Copy link
Contributor

Deathreus commented Mar 26, 2020

Not everyone is tech savvy enough to go through the process of opening ports to the public when they just want to quick-start a server for friends, this can easily be solved with the NuGet package Open.NAT

A quick and dirty mockup of the process is as follows:

var discoverer = new NatDiscoverer();
try
{
    var device = await discoverer.DiscoverDeviceAsync();
    var mappings = await device.GetAllMappingsAsync();

    if (!mappings.Any(m => m.Protocol == Protocol.Udp && m.PrivatePort == _serverData.ServerPort && m.PublicPort == _serverData.ServerPort))
    {
        var mapping = new Mapping(Protocol.Udp, _serverData.ServerPort, _serverData.ServerPort, _serverData.ServerName);
        await device.CreatePortMapAsync(mapping);
    }
}
catch
{
}

feel free to change as needed

@BattlefieldDuck
Copy link
Member

thanks for that, but I believe WindowsFirewall.cs already did this feature I think.

@Deathreus
Copy link
Contributor Author

Removing my forwarding shows otherwise

@BattlefieldDuck BattlefieldDuck added the enhancement New feature or request label Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants