C# API Internet Connected State

Posted: July 10, 2014 in C#
Tags:

C# API fonksiyonu sayesinde int baglantımızı kontrol eden program

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WindowsFormsApplication20
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

[DllImport(“wininet.dll”, CharSet = CharSet.Auto)]
extern static bool InternetGetConnectedState(ref InternetGetConnectedStateFlags Description, int ReservedValue);
[Flags]
public enum InternetGetConnectedStateFlags
{
INTERNET_CONNECTION_MODEM = 0x01,
INTERNET_CONNECTION_LAN = 0x02,
INTERNET_CONNECTION_PROXY = 0x04,
INTERNET_CONNECTION_RAS_INSTALLED = 0x10,
INTERNET_CONNECTION_OFFLINE = 0x20,
INTERNET_CONNECTION_CONFIGURED = 0x40,

}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

InternetGetConnectedStateFlags flags = 0;
bool baglantı = InternetGetConnectedState(ref flags, 0);
if (baglantı)
{
textBox1.Text = “İnternet mevcut.”;
if (flags == InternetGetConnectedStateFlags.INTERNET_CONNECTION_LAN)
{
textBox1.Text = “LAN bağlantısı mevcut.”;
}
else if (flags == InternetGetConnectedStateFlags.INTERNET_CONNECTION_MODEM)
{
textBox1.Text = “Modem bağlantısı mevcut.”;
}
else if (flags == InternetGetConnectedStateFlags.INTERNET_CONNECTION_PROXY)
{
textBox1.Text = “Proxy bağlantısı mevcut”;
}
}
else
{
textBox1.Text = “İnternet Bağlantısı yoktur”;
}

}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s