How can i get the tcp dynamicport with C# .Net Core 6? like the result of command "netsh int ipv4 show dynamicport tcp" in windows ` C:\Users\Zerek>netsh int ipv4 show dynamicport tcp
Protocol tcp dynamic port range
Startup port : 49152 Number of ports : 16384
`
need the value of "Startup port" and "Number of ports"
I have checked the relevant materials of Microsoft, and found no relevant API and class provided
CodePudding user response:
I'm not actually sure you can, I think you have to call netsh directly, which will only work on windows but if that's an option, maybe you could have a look at https://github.com/rpetz/SharpNetSH and extend it to your needs?
CodePudding user response:
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "netsh",
Arguments = "int ipv4 show dynamicport tcp",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
The code uses the System.Diagnostics namespace to execute the "netsh int ipv4 show dynamicport tcp" command and print the output to the console.
See this github post for the full code
Hope it helps