Checking online status

  • Thread starter Thread starter John Young
  • Start date Start date
J

John Young

Hi everyone,

Is there a way to check if a pc is online? I thought maybe trying to ping
a server that is on the net and somehow checking the return value. Is there
a way of doing this?

Thanks in advance for any help that you can give me.

John
 
You can try the function IsNetworkAlive with NETWORK_ALIVE_WAN flag
Here's some C# code
using System
using System.Runtime.InteropServices

namespace NetSens

/// <summary
/// Summary description for Class1
/// </summary
class Class

/// <summary
/// The main entry point for the application
/// </summary
[STAThread
static void Main(string[] args

int NETWORK_ALIVE_LAN = 0x00000001
int NETWORK_ALIVE_WAN = 0x00000002
int NETWORK_ALIVE_AOL = 0x00000004
if (IsNetworkAlive(ref NETWORK_ALIVE_WAN)
Console.WriteLine("Wan Alive")
if (IsNetworkAlive(ref NETWORK_ALIVE_LAN)
Console.WriteLine("Lan Alive")
if (IsNetworkAlive(ref NETWORK_ALIVE_AOL)
Console.WriteLine("Aol Alive")

string hostname = "www.microsoft.com"
//for simplicity, we do not care about the QocInf
if (IsDestinationReachable(hostname,IntPtr.Zero)
Console.WriteLine("{0} is reachable",hostname)
els
Console.WriteLine("{0} is not reachable", hostname)
Console.Read()


[DllImport("sensapi.dll")
private extern static bool IsNetworkAlive(ref int flags)

[DllImport("sensapi.dll")
private extern static bool IsDestinationReachable(string dest,IntPtr ptr)


</code>
 
Thank you for that information and code, I'll try it now, but it looks
ideal.

Thanks again.

John
 
Back
Top