Net-informations.com
SiteMap  | About    

Internet connection active or not ?

The Microsoft WinINet API enables applications to access standard Internet protocols, such as FTP and HTTP.

Many of you want to know if a computer has an active Internet connection before trying to connect to the internet using some communication interface. The InternetGetConnectedState function can be used to determine if there is an active internet connection exist in the computer or not .

  [DllImport("wininet.dll")]
  private extern static bool InternetGetConnectedState_
  (out int conn, int val);

InternetGetConnectedState function retrieves the connected state of the local system. A return value of TRUE from InternetGetConnectedState indicates that at least one connection to the Internet is available. The following C# program shows how to check a system has an active internet connection or not.




using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
	public partial class Form1 : Form
	{
		[DllImport("wininet.dll")]
		private extern static bool InternetGetConnectedState(out int conn, int val);

		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			int Out;
			if (InternetGetConnectedState(out Out, 0) == true)
			{
				MessageBox.Show("Connected !");
			}
			else
			{
				MessageBox.Show("Not Connected !");
			}
		}
	}
}






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.