0

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 ?

Taha Babi
  • 11
  • 4
  • If you know both machines are in the same network, you could check computer A IP addresses and choose the one from machine B that matches the same network – Cleptus Apr 14 '20 at 22:42
  • If you want to get the IP of the interface that connects to a particular IP, [check it through UDP](https://stackoverflow.com/a/27376368/529282). But usually you don't need to manually check and input them, just [broadcast](https://stackoverflow.com/questions/30091537/how-to-make-server-client-autodiscover-over-a-lan) on the lan. – Martheen Apr 14 '20 at 22:44

1 Answers1

0

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.

jscarle
  • 1,045
  • 9
  • 17