简体   繁体   中英

c# Remote ip address

i was working on c# app chatting on local network so that the computers clients and server connected to the same router

i have computer A and computer B in computer A i tried

    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());
                }
            }
        }
    }

so that B is the sever then i get this output

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 . . .

i got 6 different ips first 3 ip v6 and the second 3 are ip v4 there is addresses for vmware and lan and wifi i know that the last one is the WIFI interface ip by typing ipconfig on cmd but i want this to be automatically how to know what is the ip address of server Wifi interface?

Take a look at NetworkInterface.GetAllNetworkInterfaces . You can browse all of the adapters, find the one you want, and retrieve the network information you need there.

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