Skip to main content

Posts

Showing posts with the label C# Code

How to Check Local Machine Name and IP Address Using C#

How to check client Machine or local Machine Name and IP address using C-sharp, See the below simple example code. CODE: 1 : using System.Net; 2 : 3 : string hostName = Dns.GetHostName(); 4 : IPHostEntry ie = Dns.GetHostByName(hostName); 5 : IPAddress[] ia= ie.AddressList; 6 : 7 : MessageBox.Show("Local Machine Name : "+hostName.ToString()); 8 : MessageBox.Show("IP address Of Local Machine "+ipAddress[0].ToString());

How to Check Internet Connection Using C-Sharp

How to check internet connection using c#? Here is a simple example to find out internet connection or page response using c -Sharp CODE: 1 : Using System.Net ; 2 : try{ 3 : HttpWebRequest request= (HttpWebRequest) HttpWebRequest.Create("google.com"); 4 : HttpWebResponse response= (HttpWebResponse) request.GetResponse(); 5 : if (HttpStatusCode.OK == response.StatusCode) 6 : { 7 : //Write here your code... 8 : response.Close(); 9 : } 10 : }catch (Exception ex){ 11 : MessageBox.Show("Unable to connect"); 12 : }