I want to ask 2 questions and I would be thankful if somebody can reply.
How can I check (using C#) whether the PC is connected to LAN or not?
How can I check (using C#) my PC is connected on LAN or not
Try
System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()
You want to use Ping to check whether a PC is connected to the LAN. Here's a sample:
var ping = new Ping();
var options = new PingOptions { DontFragment = true };
//just need some data. this sends 10 bytes.
var buffer = Encoding.ASCII.GetBytes( new string( 'z', 10 ) );
var host = "127.0.0.1";
try
{
var reply = ping.Send( host, 60, buffer, options );
if ( reply == null )
{
MessageBox.Show( "Reply was null" );
return;
}
if ( reply.Status == IPStatus.Success )
{
MessageBox.Show( "Ping was successful." );
}
else
{
MessageBox.Show( "Ping failed." );
}
}
catch ( Exception ex )
{
MessageBox.Show( ex.Message );
}
To check if you own machine was connected, you could do the same to an address you know should resolve like say the domain controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With