Get Internet Connection State


I've developed a code that is intended to be used in an application extension (as with all my codes) that will tell you if the current computer has an internet connection.

To use just include the namespace given at the top of the snippet, then the connection state is a variable of custom type ConnectionState. Usage is for whatever you wish to use it for. If you're using it to display the connection state of the current computer to the user via string (label, textbox, button text, console application) just apply the .ToString() method to the end as with any other variable. It will simply print Connected or Disconnected.

About the Author

I'm a very difficult person to describe because I'm all over the place. If I could sum me up into one word it would be insane. I'm an incredibly vibrant person. I love surfing, playing guitar, programming, photography, video games, skating, snowboarding, running parkour, hanging out with friends, spending time with my girlfriend, and much more. I'm currently enrolled in college courses and pursuing jobs in my area. Ask if you want to know more.

// Required using statement:
using System.Runtime.InteropServices;

public class LAN
        private extern static bool InternetGetConnectedState(out int desc, int reserved);

	public enum ConnectionState

	public ConnectionState InternetConnection
			ConnectionState Connection = ConnectionState.Disconnected;

			int desc = 0;
			if (InternetGetConnectedState(out desc, 0))
				Connection = ConnectionState.Connected;

			return Connection;
lxXTaCoXxl 26 Posting Whiz in Training

I've upgraded this and will be re-posting it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.