c#远程IP地址

问题描述 投票:0回答:1

我正在处理本地网络上的c#应用聊天,以便计算机客户端和服务器连接到同一路由器

我有计算机A和计算机B在我尝试过的计算机A中

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Net;
    using System.Net.Sockets;

    namespace ConsoleApp3
    {
        class Program
        {
            static void Main(string[] args)
            {
                IPAddress[]ips= Dns.GetHostAddresses("Server Name");
                for (int i = 0; i < ips.Length; i++)
                {
                    Console.WriteLine(ips[i].ToString());
                }
            }
        }
    }

所以B是服务器然后我得到这个输出

fe80::c199:7c21:1a54:f326%2
fe80::94a5:59a1:bb70:3cd9%23
fe80::a150:7e47:ee9c:5194%20
192.168.40.1
192.168.133.1
192.168.1.8
Press any key to continue . . .

我有6个不同的ips前三个ip v6和第二个3 ip v4有用于vmware和lan和wifi的地址我知道最后一个是通过在cmd上键入ipconfig的WIFI接口ip但是我希望这是自动的如何知道服务器Wifi接口的IP地址是什么?

c# sockets dns wifi remote-server
1个回答
0
投票

看看NetworkInterface.GetAllNetworkInterfaces。您可以浏览所有适配器,找到所需的适配器,然后在其中检索所需的网络信息。

© www.soinside.com 2019 - 2024. All rights reserved.