how to access Computer name and Ip Address with C#
in some projects we need to access to computer name and local ip address in network . there is some way to access it with system.net Class .

how to access Computer name and Ip Address with C#
here is sample code of show computer name and ip address in winform sample project
private void btnIpAndComputerName_Click(object sender, EventArgs e) { string ComputerName = System.Environment.MachineName; lblComputerName.Text = ComputerName; IPHostEntry ipe = Dns.GetHostByName(ComputerName); IPAddress[] IpAdrress = ipe.AddressList; lblIp.Text = IpAdrress[0].ToString(); }
find locally ip in local network
// public string GetIPAddress() { string ipAddress = null; using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0)) { socket.Connect("8.8.8.8", 65530); //Google public DNS and port IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint; ipAddress = endPoint.Address.ToString(); } return ipAddress; } //
how to access Computer name and Ip Address with C#,computer name in C#,Ip Address in C#,Find Ip Address In Local With C#