Knowledge Management Banner

Knowledge Management Banner

Get ip address of pc c#

//required libraries

using System.Net;
using System.Net.Sockets;        


        public static string GetIpAddress()
        {
            string localIP;
            //It will return ti ip address of active card
            using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
            {
                socket.Connect("8.8.8.8", 65530);
                IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
                localIP = endPoint.Address.ToString();
            }
            return localIP;
        }

No comments

Powered by Blogger.