C# �nternet Ba�lant�s�n� Kontrol Etme

C# �nternet Ba�lant�s�n� Kontrol Etme

Baz� uygulamalarda, internet ba�lant�s�n�n olup olmad���n� kontrol etmemiz gerekebilir.Bunun i�in a�a��daki kodlar kullan�labilir.
�rnek :
Console projesi olu�tural�m ve �u kodlar� ekleyelim.

using System;
using System.Runtime.InteropServices;

namespace BaglantiKontrol
{
class Program
{
static void Main(string[] args)
{
BaglantiKontrol();
Console.ReadKey();
}

public static void BaglantiKontrol()
{
InternetGetConnectedStateFlags flags = 0;
bool baglanti = InternetGetConnectedState(ref flags, 0);
string sonuc = "";
if (baglanti)
sonuc = "�nternet ba�lant�s� var.";
else
sonuc = "�nternet Ba�lant�s� Yok";
Console.Write(sonuc);
Console.ReadKey();
}

[DllImport("wininet.dll", CharSet = CharSet.Auto)]
extern static bool InternetGetConnectedState(ref InternetGetConnectedStateFlags Description, int ReservedValue);

[Flags]
public enum InternetGetConnectedStateFlags
{
INTERNET_CONNECTION_MODEM = 0x01, //Yerel sistem �nternet'e ba�lanmak i�in bir modem kullan�r.
INTERNET_CONNECTION_LAN = 0x02, //Yerel sistem �nternet'e ba�lanmak i�in bir yerel alan a�� kullan�r.
INTERNET_CONNECTION_PROXY = 0x04, //Yerel sistem Internet'e ba�lanmak i�in bir proxy sunucusu kullan�yor.
INTERNET_CONNECTION_RAS_INSTALLED = 0x10, //Yerel sistemde RAS kuruldu
INTERNET_CONNECTION_OFFLINE = 0x20, //Yerel sistem �evrimd��� modda.
INTERNET_CONNECTION_CONFIGURED = 0x40, //Yerel sistem, �nternet'le ge�erli bir ba�lant�ya sahiptir, ancak o anda ba�l� olabilir veya olmayabilir.
INTERNET_CONNECTION_MODEM_BUSY = 0x08 //Art�k kullan�lm�yor.
}
}
}

Yorum Gönder

Recent Posts

https://www.rentacarantalya.net/
 
DeL��� : Film izle
Copyright © 2012 - 2013. DenemeTv

Tasar�m: G�ncel Bilgi