<tfoot id='q7TrM'></tfoot>
  1. <legend id='q7TrM'><style id='q7TrM'><dir id='q7TrM'><q id='q7TrM'></q></dir></style></legend>
    1. <i id='q7TrM'><tr id='q7TrM'><dt id='q7TrM'><q id='q7TrM'><span id='q7TrM'><b id='q7TrM'><form id='q7TrM'><ins id='q7TrM'></ins><ul id='q7TrM'></ul><sub id='q7TrM'></sub></form><legend id='q7TrM'></legend><bdo id='q7TrM'><pre id='q7TrM'><center id='q7TrM'></center></pre></bdo></b><th id='q7TrM'></th></span></q></dt></tr></i><div id='q7TrM'><tfoot id='q7TrM'></tfoot><dl id='q7TrM'><fieldset id='q7TrM'></fieldset></dl></div>

      <small id='q7TrM'></small><noframes id='q7TrM'>

        <bdo id='q7TrM'></bdo><ul id='q7TrM'></ul>

      .NET Core 2.x 如何获取当前活动的本地网络 IPv4 地址?

      时间:2023-07-11

      <small id='zjDvy'></small><noframes id='zjDvy'>

      1. <i id='zjDvy'><tr id='zjDvy'><dt id='zjDvy'><q id='zjDvy'><span id='zjDvy'><b id='zjDvy'><form id='zjDvy'><ins id='zjDvy'></ins><ul id='zjDvy'></ul><sub id='zjDvy'></sub></form><legend id='zjDvy'></legend><bdo id='zjDvy'><pre id='zjDvy'><center id='zjDvy'></center></pre></bdo></b><th id='zjDvy'></th></span></q></dt></tr></i><div id='zjDvy'><tfoot id='zjDvy'></tfoot><dl id='zjDvy'><fieldset id='zjDvy'></fieldset></dl></div>
      2. <tfoot id='zjDvy'></tfoot>
          <tbody id='zjDvy'></tbody>
        <legend id='zjDvy'><style id='zjDvy'><dir id='zjDvy'><q id='zjDvy'></q></dir></style></legend>

            • <bdo id='zjDvy'></bdo><ul id='zjDvy'></ul>

                本文介绍了.NET Core 2.x 如何获取当前活动的本地网络 IPv4 地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在其上运行 WebService.就像我可以在 cmd.exe >ipconfig:

                On which is running the WebService. Like the one I can get in cmd.exe > ipconfig:

                我想要实现的是Kestrel的自动IP配置,比如:

                What I would like to achieve is automatic IP configuration of Kestrel, like:

                .UseKestrel(opts => 
                    { 
                        opts.Listen(/*LocalIPv4ActiveAddress*/, 5000);
                    }) 
                

                所以我可以用不同的活动网络接口(WiFi || 以太网)和不同的本地网络 IP 地址切换我的开发机器.

                So I can switch my development machines with different active network interfaces (WiFi || Ethernet) and different local network IP addresses.

                推荐答案

                你可以试试这样的:

                // order interfaces by speed and filter out down and loopback
                // take first of the remaining
                var firstUpInterface = NetworkInterface.GetAllNetworkInterfaces()
                    .OrderByDescending(c => c.Speed)
                    .FirstOrDefault(c => c.NetworkInterfaceType != NetworkInterfaceType.Loopback && c.OperationalStatus == OperationalStatus.Up);
                if (firstUpInterface != null) {
                    var props = firstUpInterface.GetIPProperties();
                    // get first IPV4 address assigned to this interface
                    var firstIpV4Address = props.UnicastAddresses
                        .Where(c => c.Address.AddressFamily == AddressFamily.InterNetwork)
                        .Select(c => c.Address)
                        .FirstOrDefault();
                }
                

                这篇关于.NET Core 2.x 如何获取当前活动的本地网络 IPv4 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:JsonSerializer.Deserialize 失败 下一篇:如何将项目引用添加到 ASP.NET Core 1.0 MVC 项目

                相关文章

                <tfoot id='CMVUu'></tfoot>

                <small id='CMVUu'></small><noframes id='CMVUu'>

              • <legend id='CMVUu'><style id='CMVUu'><dir id='CMVUu'><q id='CMVUu'></q></dir></style></legend>

                  1. <i id='CMVUu'><tr id='CMVUu'><dt id='CMVUu'><q id='CMVUu'><span id='CMVUu'><b id='CMVUu'><form id='CMVUu'><ins id='CMVUu'></ins><ul id='CMVUu'></ul><sub id='CMVUu'></sub></form><legend id='CMVUu'></legend><bdo id='CMVUu'><pre id='CMVUu'><center id='CMVUu'></center></pre></bdo></b><th id='CMVUu'></th></span></q></dt></tr></i><div id='CMVUu'><tfoot id='CMVUu'></tfoot><dl id='CMVUu'><fieldset id='CMVUu'></fieldset></dl></div>
                    • <bdo id='CMVUu'></bdo><ul id='CMVUu'></ul>